Beej's Guide Network to Programming series serialization 12

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.