Shutdown and close of sockets

Source: Internet
Author: User

Shutdown prototypes

int shutdown (int socket, int how); socket specifies the socket's file descriptor how to specify the type of shutdown SHUT_RD

Prohibit read operation

SHUT_WR prohibit write operation Shut_rdwr Read and write Forbidden

Close prototypes

int close (int fd); Close is a kernel function that closes the file handle that the process occupies, each file handle in the kernel has a reference count, each process that opens the file handle counts +1, and each call to close will close the file descriptor that the process occupies, and the reference count in the kernel-1.

Difference

Shutdown directly on the socket connection, after calling shutdown, all file descriptors associated with the socket are affected (not readable or writable, or neither), that is, the impact is cross-process, shutdown does not close the socket, The socket is passively closed at the associated file descriptor kernel count of 0 o'clock.

Close works on the file descriptor of the process open, and after close the process will not be able to access the socket, the socket will turn off when the reference count becomes 0 o'clock, and if multiple processes access the file descriptor of the same socket, one of the processes calls close (SOCKFD Other processes can proceed with socket communication.

Shutdown and close of sockets

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.