close Function

 < Day Day Up > 



close Function

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 > 



BSD Sockets Programming from a Multi-Language Perspective
Network Programming for Microsoft Windows , Second Edition (Microsoft Programming Series)
ISBN: 1584502681
EAN: 2147483647
Year: 2003
Pages: 225
Authors: Jim Ohlund

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net