| < Day Day Up > |
|
The close function is used to mark the socket as closed so that no further activity may occur on it. This activity specifically refers to Application layer activities, as the Sockets layer will continue to try to send any remaining data in the send queue. Therefore, once the socket is closed, an application may no longer call any Sockets API functions using the socket as an argument. The close function has the following prototype:
int close( int sock );
The sock argument refers to a previously created socket through the socket function. Success is indicated by return of zero, while a –1 return represents an error. It’s important to close unused sockets because they tie up resources not only on the local host, but also on the remote peer for a stream-based socket.
After the close function is performed on a stream socket and no data remains to be sent to the peer socket, the socket will begin the connection termination sequence to close both ends of the connection.
| < Day Day Up > |
|