5.9. close () and shutdown () --- don't let me see your face again!
You have been sending (send () and receiving (recv () data all day. Now you are going to close your socket descriptor. This is simple. You can use the close () function of the general Unix file descriptor:
Int close (sockfd );
It will prevent reading and writing more data on the socket. Any enterprise image that reads or writes a socket on the other end will return an error message.
If you want to have more control over how to close the socket, you can use the function shutdown (). It allows you to disable communication in a certain direction or two-way communication (just like close (). You can use:
Int shutdown (intsockfd, int how );
Sockfd is the description of the socket file you want to close. The value of how is one of the following:
0-unacceptable
1-cannot be sent
2-sending and receiving are not allowed (the same as close)
If shutdown () succeeds, 0 is returned. If the shutdown fails,-1 is returned (errno is set at the same time .) If you use shutdown () in a connectionless datagram socket, it is only for sending () and recv () cannot be used (remember that you can use them after using connect in the datagram socket ).
From the column xiaobin_HLJ80