[ Team LiB ] Previous Section Next Section

5.3 TCP Echo Server: str_echo Function

The function str_echo, shown in Figure 5.3, 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

89 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 5.2

    [ Team LiB ] Previous Section Next Section