Previous: http://www.bkjia.com/kf/201112/115475.html
5.5. listen () --- if there is a "person", please call me?
It's time to change the content. If you don't want to connect to a remote address, or just kick it off, you need to wait for access requests and process them in various ways. The process is divided into two steps: first, listen to -- listen (), and then, you accept -- accept ()
Function prototype:
Int listen (intsockfd, int backlog );
Sockfd is the socket file descriptor returned by calling socket. Backlog is the number of connections allowed in the queue. What does it mean? The connection is waiting in the queue until you accept the connection (accept () Please refer to the following article. They are limited to the number of queues allowed. The maximum number of systems is 20. You can also set it to 5 to 10.
Like other functions,-1 is returned when an error occurs and the global error variable errno is set.
As you may imagine, before you call listen (), you can call bind () or let the kernel select a port. If you want to listen for incoming connections, the system call sequence may be as follows:
Getaddrinfo ();
Socket ();
Bind ();
Listen ();
/* Accept () goeshere */
Because it is quite clear, I will not give an example here. (The code in the accept () chapter will be more complete .) The really troublesome part is in accept ().
From the column xiaobin_HLJ80