The close and shutdown differences in the socket __socket

Source: Internet
Author: User
It is clear that the two functions are different. Close

Closes the socket ID for this process, but the link is still open. How to understand. We know that the socket descriptor is a reference to the socket object in the kernel. The formal socket descriptor for the close operation can be understood to break the relationship between the current process and the socket object in the kernel. But other processes can also establish relationships with this socket object. Of course that means the connection is open (because other processes can read and write data through the socket) shutdown

Break the socket link, read the time may be detective to the EOF Terminator, write when you may receive a sigpipe signal, this signal may not until the socket buffer is filled to receive, shutdown there is a way to close the parameters,0 can not be read, 1 can not write, 2 read and write can not.

==================================================================================================
Socket shutdown in multiple processes, close using
When all the data operations are finished, you can call the close () function to release the socket, stopping any data operations on the socket:
Close (SOCKFD);

You can also call the shutdown () function to close the socket. This function allows you to stop data transfers only in one direction and the data transfer in a single direction continues . For example, you can close the write operation of a socket and allow the data to continue to be accepted on the socket until all data is read.
The following is the
int shutdown (int sockfd,int how) excerpt from the UNIX network programming; The
SOCKFD is the descriptor for the socket that needs to be closed. Parameter how allows you to select the following ways for shutdown operations:
Shut_rd: Closes the read end of a connection. That is, the socket no longer accepts data, and any data that is currently accepting buffers in the socket will be discarded. The process will not be able to issue any read operation on this socket. Any data received after the call to the TCP socket will be confirmed and silently discarded.
SHUT_WR: Closes the write end of the connection, the process cannot write on this socket
Shut_rdwr: It is equivalent to calling shutdown two times: First, SHUT_RD, and then SHUT_WR
use close to abort a connection. However, it only reduces the reference number of the descriptor, does not close the connection directly, and closes the connection only if the reference number of the descriptor is 0 o'clock. The
shutdown can directly close the descriptor without regard to the reference number of the descriptor, optionally aborting a connection in one direction. Note: If more than one process shares a socket, close is called every time, and the count is reduced by 1 until the count is 0 o'clock, where the process calls close and the socket is freed. In multiple processes, if a process shutdown (SFD, shut_rdwr), the other processes will not be able to communicate. If a process close (SFD) will not

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.