fdTable[fd].path = NULL;
break;
case FD_PIPE_ASYNC:
- CloseHandle((HANDLE)fdTable[fd].fid.value);
break;
default:
break;
if (*bindPath != ':')
{
char * p = strchr(bindPath, ':');
- int len = p - bindPath + 1;
+ if (p) {
+ int len = p - bindPath + 1;
- host = malloc(len);
- strncpy(host, bindPath, len);
- host[len] = '\0';
+ host = malloc(len);
+ if (!host) {
+ fprintf(stderr, "Unable to allocate memory\n");
+ return -1;
+ }
+ strncpy(host, bindPath, len);
+ host[len-1] = '\0';
+ }
}
hp = gethostbyname(host ? host : LOCALHOST);
return -1;
}
- if (! connect(sock, (struct sockaddr *) &sockAddr, sockLen))
+ if (connect(sock, (struct sockaddr *) &sockAddr, sockLen) == SOCKET_ERROR)
{
closesocket(sock);
return -1;
else
{
fdTable[fd].Errno = GetLastError();
+ ret = -1;
}
break;
case FD_PIPE_ASYNC:
case FD_FILE_SYNC:
case FD_FILE_ASYNC:
- break;
-
- case FD_SOCKET_SYNC:
+ /*
+ * CloseHandle returns: TRUE success, 0 failure
+ */
+ if (CloseHandle(fdTable[fd].fid.fileHandle) == FALSE)
+ ret = -1;
+ break;
+ case FD_SOCKET_SYNC:
case FD_SOCKET_ASYNC:
/*
* Closing a socket that has an async read outstanding causes a
* tcp reset and possible data loss. The shutdown call seems to
* prevent this.
*/
- shutdown(fdTable[fd].fid.sock, 2);
- /*
+
+ /* shutdown(fdTable[fd].fid.sock, SD_BOTH); */
+
+ {
+ char buf[16];
+ int r;
+
+ shutdown(fdTable[fd].fid.sock,SD_SEND);
+
+ do
+ {
+ r = recv(fdTable[fd].fid.sock,buf,16,0);
+ } while (r > 0);
+ }
+ /*
* closesocket returns: 0 success, SOCKET_ERROR failure
*/
if (closesocket(fdTable[fd].fid.sock) == SOCKET_ERROR)
- ret = -1;
+ ret = -1;
break;
default:
return -1; /* fake failure */
ASSERT(fdTable[fd].type == FD_SOCKET_ASYNC
|| fdTable[fd].type == FD_SOCKET_SYNC);
- if (shutdown(fdTable[fd].fid.sock,0) == SOCKET_ERROR)
+ if (shutdown(fdTable[fd].fid.sock,SD_RECEIVE) == SOCKET_ERROR)
ret = -1;
return ret;
}
if (fdTable[fd].type == FD_SOCKET_SYNC && flags == O_NONBLOCK) {
if (ioctlsocket(fdTable[fd].fid.sock, FIONBIO, &pLong) ==
- SOCKET_ERROR) {
+ SOCKET_ERROR) {
//exit(WSAGetLastError());
SetLastError(WSAGetLastError());
return;