| < 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 > |
|