shutdown Function

 < Day Day Up > 



shutdown Function

The shutdown function is an advanced form of the close function (from Chapter 3, Standard BSD API Functions) that provides greater control over the process of closing down a socket connection. In most cases, a close will suffice to end a connection, but there are cases to consider for shutdown. The prototype for the shutdown function is defined as:

#include <sys/socket.h> int shutdown( int sock, int how );

The shutdown function operates on a currently connected socket, as defined by sock. The how parameter is used to determine in what manner the shutdown function should operate. Three values are possible for the how parameter, as shown in Table 4.4.

Table 4.4: RANGE OF VALUES FOR THE how PARAMETER OF shutdown

Value

Description

0

Subsequent receives are not permitted

1

Subsequent writes are not permitted

2

Subsequent receives and writes are not permitted (close)

The shutdown function historically was a way to close a socket regardless of the number of users of the socket [Stevens98].

If the shutdown function is called with a how of 0, the application may no longer read from the socket, but data is still permitted to be sent. Received data is discarded, though the sender may continue to send while the peer application is unaware of this situation. A shutdown with a how of 1 means that the socket can still be read, but writes are not permitted (discarded). Any data in the socket’s send buffer will continue to be sent. This scenario (writes not permitted) is called a TCP half-close. Finally, a how of 2 is similar to a close because both reading and writing are no longer permitted through the socket.



 < 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