void
its(inet_addr ina, port_no pno)
skt l = tcp_listener(ina, pno)
while (true)
skt c = accept(l)
msg m
while read_msg(c, m)
write_msg(c, reply(m))
close(c)
void pts(inet_addr ina, port_no pno)
skt s = tcp_listener(ina, pno)
while true
skt c = accept(s)
switch fork()
case 0
close(s)
msg m
while read_msg(c, m)
write_msg(c, reply(m))
close(c)
break
case -1
perror("fork() failed")
exit(EXIT_FAILURE)
default
close(c)
void reaper(int sig)
while (waitpid(-1, NULL, WNOHANG) > 0) { }
void pts(inet_addr ina, port_no pno)
skt s = tcp_listener(ina, pno)
signal(SIGCHLD, reaper)
while (true)
skt c = accept(s)
// as before
accept().
skt accept(skt s)
skt a
while (true)
a.s = accept(s.s, NULL, NULL)
if (a.s > -1) break
if (errno == EINTR) continue
perror("accept() failed")
exit(EXIT_FAILURE)
return a
void ius(inet_addr ina, port_no pno)
skt s = udp_socket(ina, pno)
msg m
end_point sender
while read_msg(s, m, sender)
write_msg(s, reply(m), sender)
void pus(inet_addr ina, port_no pno)
skt s = udp_socket(ina, pno)
msg m
end_point sender
signal(SIGCHLD, reaper)
while read_msg(s, m, sender)
switch fork()
case 0
write_msg(s, reply(m), sender)
close(s)
exit(EXIT_SUCCESS)
case -1
perror("fork() failed")
exit(EXIT_FAILURE)
close(s)
This page last modified on 3 March 2003.