Ignoring Peer Socket Closure

 < Day Day Up > 



Ignoring peer socket closure is related to ignoring return statuses, but we cover this separately because it is one of the most common errors. The read function returns the number of octets that were read from a socket or a –1 if an error occurred. Additionally, a zero return commonly represents the end-of-file indication, which for a socket represents peer socket closure. The following code snippet illustrates this functionality:

bytesRead = read( clisock, buffer, BUF_SIZE ); if (bytesRead > 0) {     /* Successful return, data in buffer */ } else {     /* 0 or –1 returned, either way, close the socket */ }

The read function permits testing the socket for closure and once detected can produce the necessary local socket closure. Failure to deal with peer socket closure can result in subsequent error behavior that may not be easily traceable to the closure condition.



 < 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