version 1.5 | | version 1.6 |
---|
| | |
| | |
/* | | /* |
* static char *rcsid_sockets_c = | | * static char *rcsid_sockets_c = |
* "$Id: lowlevel.c,v 1.5 2001/04/06 00:43:40 michtoen Exp $"; | | * "$Id: lowlevel.c,v 1.6 2001/04/06 19:08:08 michtoen Exp $"; |
*/ | | */ |
| | |
/* | | /* |
| | |
} | | } |
/* We already have a partial packet */ | | /* We already have a partial packet */ |
if (sl->len<2) { | | if (sl->len<2) { |
#ifdef WIN32 // ***WIN32 SockList_ReadPacket: change read() to recv() | | #ifdef WIN32 /* ***WIN32 SockList_ReadPacket: change read() to recv() */ |
| | |
stat=recv(fd, sl->buf + sl->len, 2-sl->len,0); | | stat=recv(fd, sl->buf + sl->len, 2-sl->len,0); |
| | |
| | |
/* In non blocking mode, EAGAIN is set when there is no | | /* In non blocking mode, EAGAIN is set when there is no |
* data available. | | * data available. |
*/ | | */ |
#ifdef WIN32 // ***WIN32 SockList_ReadPacket: error handling for win32 | | #ifdef WIN32 /* ***WIN32 SockList_ReadPacket: error handling for win32 */ |
if ((stat==-1) && WSAGetLastError() !=WSAEWOULDBLOCK) { | | if ((stat==-1) && WSAGetLastError() !=WSAEWOULDBLOCK) { |
if(WSAGetLastError() == WSAECONNRESET) | | if(WSAGetLastError() == WSAECONNRESET) |
LOG(llevDebug,"Connection closed by client\n"); | | LOG(llevDebug,"Connection closed by client\n"); |
else | | else |
{ | | { |
perror("ReadPacket got an error."); //***win32 <- for what is this instead of log? | | perror("ReadPacket got an error."); /* ***win32 <- for what is this instead of log? */ |
LOG(llevDebug,"ReadPacket got error %d, returning 0\n",WSAGetLastError()); | | LOG(llevDebug,"ReadPacket got error %d, returning 0\n",WSAGetLastError()); |
} | | } |
return -1; // kick this user! | | return -1; /* kick this user! */ |
} | | } |
#else | | #else |
if (errno != EAGAIN && errno !=EWOULDBLOCK) { | | if (errno != EAGAIN && errno !=EWOULDBLOCK) { |
| | |
* closing the socket anyways, then reading this extra 100 bytes | | * closing the socket anyways, then reading this extra 100 bytes |
* shouldn't hurt. | | * shouldn't hurt. |
*/ | | */ |
#ifdef WIN32 // ***win32 SockList_ReadPacket: change read() to recv() | | #ifdef WIN32 /* ***win32 SockList_ReadPacket: change read() to recv() */ |
recv(fd, sl->buf+2, 100, 0); | | recv(fd, sl->buf+2, 100, 0); |
#else | | #else |
read(fd, sl->buf+2, 100); | | read(fd, sl->buf+2, 100); |
#endif // end win32 | | #endif /* end win32 */ |
| | |
/* return error so the socket is closed */ | | /* return error so the socket is closed */ |
return -1; | | return -1; |
} | | } |
do { | | do { |
#ifdef WIN32 // ***win32 SockList_ReadPacket: change read() to recv() | | #ifdef WIN32 /* ***win32 SockList_ReadPacket: change read() to recv() */ |
stat = recv(fd, sl->buf+ sl->len, toread, 0); | | stat = recv(fd, sl->buf+ sl->len, toread, 0); |
#else | | #else |
do { | | do { |
| | |
#endif | | #endif |
if (stat<0) { | | if (stat<0) { |
| | |
#ifdef WIN32 // ***win32 SockList_ReadPacket: change error handling for win32 | | #ifdef WIN32 /* ***win32 SockList_ReadPacket: change error handling for win32 */ |
if ((stat==-1) && WSAGetLastError() !=WSAEWOULDBLOCK) { | | if ((stat==-1) && WSAGetLastError() !=WSAEWOULDBLOCK) { |
if(WSAGetLastError() == WSAECONNRESET) | | if(WSAGetLastError() == WSAECONNRESET) |
LOG(llevDebug,"Connection closed by client\n"); | | LOG(llevDebug,"Connection closed by client\n"); |
| | |
perror("ReadPacket got an error."); | | perror("ReadPacket got an error."); |
LOG(llevDebug,"ReadPacket got error %d, returning 0\n",WSAGetLastError()); | | LOG(llevDebug,"ReadPacket got error %d, returning 0\n",WSAGetLastError()); |
} | | } |
return -1; // kick this user! | | return -1; /* kick this user! */ |
} | | } |
#else | | #else |
if (errno != EAGAIN && errno !=EWOULDBLOCK) { | | if (errno != EAGAIN && errno !=EWOULDBLOCK) { |
| | |
max = SOCKETBUFSIZE - ns->outputbuffer.start; | | max = SOCKETBUFSIZE - ns->outputbuffer.start; |
if (ns->outputbuffer.len<max) max = ns->outputbuffer.len; | | if (ns->outputbuffer.len<max) max = ns->outputbuffer.len; |
| | |
#ifdef WIN32 // ***win32 write_socket_buffer: change write() to send() | | #ifdef WIN32 /* ***win32 write_socket_buffer: change write() to send() */ |
amt=send(ns->fd, ns->outputbuffer.data + ns->outputbuffer.start, max,0); | | amt=send(ns->fd, ns->outputbuffer.data + ns->outputbuffer.start, max,0); |
#else | | #else |
do { | | do { |
| | |
| | |
if (amt < 0) { /* We got an error */ | | if (amt < 0) { /* We got an error */ |
| | |
#ifdef WIN32 // ***win32 write_socket_buffer: change error handling | | #ifdef WIN32 /* ***win32 write_socket_buffer: change error handling */ |
if (amt == -1 && WSAGetLastError() !=WSAEWOULDBLOCK) { | | if (amt == -1 && WSAGetLastError() !=WSAEWOULDBLOCK) { |
LOG(llevError,"New socket write failed (wsb) (%d).\n", WSAGetLastError()); | | LOG(llevError,"New socket write failed (wsb) (%d).\n", WSAGetLastError()); |
#else | | #else |
| | |
/* If we manage to write more than we wanted, take it as a bonus */ | | /* If we manage to write more than we wanted, take it as a bonus */ |
while (len>0) { | | while (len>0) { |
| | |
#ifdef WIN32 // ***win32 Write_To_Socket: change write() to send() | | #ifdef WIN32 /* ***win32 Write_To_Socket: change write() to send() */ |
amt=send(ns->fd, pos, len,0); | | amt=send(ns->fd, pos, len,0); |
#else | | #else |
do { | | do { |
| | |
#endif | | #endif |
| | |
if (amt < 0) { /* We got an error */ | | if (amt < 0) { /* We got an error */ |
#ifdef WIN32 // ***win32 Write_To_Socket: change error handling | | #ifdef WIN32 /* ***win32 Write_To_Socket: change error handling */ |
if (amt == -1 && WSAGetLastError() !=WSAEWOULDBLOCK) { | | if (amt == -1 && WSAGetLastError() !=WSAEWOULDBLOCK) { |
LOG(llevError,"New socket write failed WTS (%d).\n",WSAGetLastError()); | | LOG(llevError,"New socket write failed WTS (%d).\n",WSAGetLastError()); |
#else | | #else |
if (errno !=EWOULDBLOCK) { | | if (errno !=EWOULDBLOCK) { |
LOG(llevError,"New socket write failed WTS (%d: %s).\n", // ---WIN32 | | LOG(llevError,"New socket write failed WTS (%d: %s).\n", /* ---WIN32 */ |
errno, strerror_local(errno)); | | errno, strerror_local(errno)); |
#endif | | #endif |
ns->status=Ns_Dead; | | ns->status=Ns_Dead; |