July 24, 2011, 3:15 p.m.
posted by ersatz
5.3 TCP Echo Server: str_echo Function
The function str_echo, shown in Figure, performs the server processing for each client: It reads data from the client and echoes it back to the client.
Read a buffer and echo the buffer
8–9 read reads data from the socket and the line is echoed back to the client by writen. If the client closes the connection (the normal scenario), the receipt of the client's FIN causes the child's read to return 0. This causes the str_echo function to return, which terminates the child in Figure