C. Disable socket

Source: Internet
Author: User

There are two methods for C to disable socket:

1. Shutdown

# Include <sys/socket. h>

Int Shutdown (INT sockfd, int how );

There are three methods for how:

Shut_rd (0): Disable the READ function on sockfd. This option does not allow sockfd to perform read operations.

Shut_wr (1): Disable the FD write function. This option does not allow FD to write.

Shut_rdwr (2): Disable the FD read/write function.

If it succeeds, 0 is returned. if the error is-1, the error code errno: ebadf indicates that sockfd is not a valid descriptor; enotconn indicates that sockfd is not connected; enotsock indicates that sockfd is a file descriptor rather than a socket descriptor.

Ii. Close

# Include <unistd. h>

Int close (int fd );

Disable read/write.

If the call succeeds, 0 is returned, and-1 is returned. The error code errno: ebadf indicates that FD is not a valid descriptor. eintr indicates that the close function is interrupted by signals. EIO indicates an IO error.

Note:

1. Shutdown can be disabled in one way, but close cannot.

2. When multiple threads share/call the same socket, close will only be reduced by 1, and the socket will not be closed until it is reduced to 0, while shutdown will ignore how many threads are in use, directly close the socket.


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.