The use _c language of accept () function and shutdown () function in C language

Source: Internet
Author: User
Tags error code socket

C language Accept () function: Accept socket connection
header file:

#include <sys/types.h>  #include <sys/socket.h>

To define a function:

int accept (int s, struct sockaddr * addr, int * Addrlen);

Function Description: Accept () is used to accept the socket connection of the parameter S. The socket of the parameter s must be processed by the bind (), listen () function First, when the connection comes in, accept () will return a new socket processing code, then the data transmission and reading is through the new socket processing, and the original parameter s socket Can continue to use accept () to accept new wiring requirements. When the connection succeeds, the structure of the parameter addr is populated by the system into the address data of the remote host, and the parameter addrlen is the SCOKADDR structure length. Refer to bind () for the definition of the sockaddr of a mechanism.

Return value: Succeeds returns the new socket processing code, the failure returns-1, the reason for the error is stored in the errno.

Error code:
1, EBADF parameter s is not legitimate socket processing code.
2. The Efault parameter addr pointer points to an inaccessible memory space.
3, Enotsock parameter S is a document description word, not socket.
4, Eopnotsupp specified socket is not a sock_stream.
5. The eperm firewall rejects this connection.
6, ENOBUFS system buffer memory is insufficient.
7, Enomem core memory is not enough.

C language Shutdown () function: terminating socket communication
header file:

#include <sys/socket.h>

To define a function:

int shutdown (int s, int how);

Function Description: Shutdown () is used to terminate the socket connection specified by the parameter S. The parameter S is the socket processing code in the line, and the parameter how has the following several situations:

    • How=0 terminates the read operation.
    • How=1 Terminate the transfer operation
    • how=2 termination Read and transfer operation

Return value: Success returns 0, failure returns-1, the reason for the error is in errno.

Error code:
1, EBADF parameter s is not a valid socket processing code
2, the Enotsock parameter s is a document descriptive word, not the socket
3, enotconn parameter s specified socket is not wired

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.