This preview shows page 1. Sign up to view the full content.
Unformatted text preview: he client end of a connection. A server calls the listen function to tell the kernel that the descriptor will be used by a server instead of a client.
#include <sys/socket.h> int listen(int sockfd, int backlog);
returns: 0 if OK, -1 on error The listen function converts sockfd from an active socket to a listening socket that can accept connection requests from clients. The backlog argument is a hint about the number of outstanding connection requests that the kernel should queue up before it starts to refuse requests. The exact meaning of the backlog argument requires an understanding of TCP/IP that is beyond our scope. We will typically set it to a large value, such as 1024. Figure 12.25 shows our open listenfd helper function that opens and returns a listening socket ready to receive client connection requests on the well-known port port. After we create the listenfd socket descriptor (line 11), we use the setsockopt function (not described here) to conﬁgure the server so that it can be terminated and restarted immediately (lines 14-15). By default, a restarted server...
View Full Document