Despite our best efforts to avoid errors in the text, and sample applications that accompany Windows Sockets Network Programming, a few slipped by. Our apologies for any confusion or inconvenience that these might have caused. This page tries to make amends for our oversights. Also watch the descriptions of our sample applications for notes of any significant enhancements.
We would greatly appreciate hearing about any other errors, or points of confusion that you come across. Please mail them to us at rcq@sockets.com. If you don't see them here, then we don't know about them.
Unlike the SOCK_STREAM or SOCK_DGRAM socket types, when you select the socket type SOCK_RAW there are no defaults. You must always specify the protocol value (as we describe in Chapter 16).
You can hardcode the value for the protocol parameter...
.
case FD_WRITE:
/* this event occurs when we're initially connected
* and subsequently whenever send() fails with an
* WSAEWOULDBLOCK error */
for (nBytesXferred=0; nBytesToXfer-nBytesXferred; ) {
nRet = send (s, /* send string */
(LPSTR)&(achOutBuf[nBytesXferred]),
nBytesToXfer - nBytesXferred,
0);
if (nRet == SOCKET_ERROR) {
if (WSAGetLastError() != WSAEWOULDBLOCK) {
<report error> /* fatal error */
<abort the connection>
}
break;
} else {
nBytesXferred += nRet; /* tally bytes sent */
}
}
/* if all bytes are sent, close the connection gracefully */
if ((nBytesToXfer - nBytesXferred) <= 0) {
<call shutdown (how=1)>
<loop on recv() until *any* error occurs>
<fall through to close the socket>
} else {
break;
}
case FD_CLOSE:
} else {
if (nAppState & STATE_GETTING_LENGTH) {
nDataLen += nDataRecvd;
if (nDataLen >= DATALEN) { /* we got the data length */
nDataToRead = ((int)*(achDataIn))-DATALEN-nDataRecvd;
nAppState = STATE_GETTING_DATA;
nDataLen = 0;
} else {
nDataToRead -= nDataRecvd; /* update bytes to read */
}
} else if (nAppState & STATE_GETTING_DATA) {
nDataToRead -= nDataRecvd; /* update bytes to read */
}
if (nDataToRead <= 0) { /* we got it all! */
nDataToRead = MINDATASIZE + DATALEN; /* reset things */
nAppState = STATE_GETTING_LENGTH;
lpDataIn = (char FAR *)achDataIn;
}
}
Last updated 10/02/98 by Bob Quinn