SHARE
TWEET

closesocket.patch

kosh Aug 29th, 2013 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. diff --git a/nl-filesys.c b/nl-filesys.c
  2. index 9af952c..f88d4d9 100644
  3. --- a/nl-filesys.c
  4. +++ b/nl-filesys.c
  5. @@ -85,6 +85,7 @@ int setenv (const char *name, const char *value, int replace);
  6.  
  7.  #ifndef WINDOWS
  8.  #include <sys/socket.h>
  9. +#define closesocket(s) close(s)
  10.  #define SOCKET_ERROR -1
  11.  #define INVALID_SOCKET -1
  12.  #endif
  13. @@ -1347,7 +1348,7 @@ SPAWN_LIST * spawnList;
  14.  while(mySpawnList != NULL)
  15.      {
  16.      if(sockFlag)
  17. -        close(mySpawnList->socket);
  18. +        closesocket(mySpawnList->socket);
  19.      spawnList = mySpawnList->next;
  20.      free(mySpawnList);
  21.      mySpawnList = spawnList;
  22. @@ -1476,7 +1477,7 @@ if(forkPid == 0) /* the child process */
  23.      srandom(getpid());
  24.      /* get parent pid */
  25.      parentPid = pid;
  26. -    if(sockets[0]) close(sockets[0]);
  27. +    if(sockets[0]) closesocket(sockets[0]);
  28.      thisSocket = sockets[1];
  29.      /* purge inherited spawnlist */
  30.      purgeSpawnList(FALSE);
  31. @@ -1485,7 +1486,7 @@ if(forkPid == 0) /* the child process */
  32.      exit(0);
  33.      }
  34.  
  35. -if(sockets[1]) close(sockets[1]);
  36. +if(sockets[1]) closesocket(sockets[1]);
  37.  addSpawnedChild(address, symPtr, forkPid, sockets[0]);
  38.  
  39.  return(stuffInteger(forkPid));
  40. diff --git a/nl-sock.c b/nl-sock.c
  41. index 00efa7b..8c2e2e7 100644
  42. --- a/nl-sock.c
  43. +++ b/nl-sock.c
  44. @@ -111,10 +111,9 @@ struct icmp
  45.  #define MAX_PENDING_CONNECTS 128
  46.  #define NO_FLAGS_SET 0
  47.  
  48. -#ifdef WINDOWS
  49. -#define close closesocket
  50. -#else
  51. -#define SOCKET_ERROR -1
  52. +#ifndef WINDOWS
  53. +#define closesocket(s) close(s)
  54. +#define SOCKET_ERROR   -1
  55.  #define INVALID_SOCKET -1
  56.  #endif
  57.  
  58. @@ -223,7 +222,7 @@ while(session)
  59.              previous->next = session->next;
  60.          if(session->stream != NULL)
  61.              fclose(session->stream);
  62. -        else close(handle);
  63. +        else closesocket(handle);
  64.          free((char *)session);
  65.          return(TRUE);
  66.          }
  67. @@ -481,7 +480,7 @@ strncpy(remote_sun.sun_path, path, sizeof(remote_sun.sun_path) - 1);
  68.  remote_sun.sun_path[sizeof (remote_sun.sun_path) - 1] = '\0';
  69.  if (connect(sock, (struct sockaddr *)&remote_sun, SUN_LEN(&remote_sun)) == -1)
  70.      {
  71. -    close(sock);
  72. +    closesocket(sock);
  73.      netErrorIdx = ERR_INET_CONNECT_FAILED;
  74.      return(SOCKET_ERROR);
  75.      }
  76. @@ -650,7 +649,7 @@ return(sock);
  77.  
  78.  CONNECT_FAILED:
  79.  freeaddrinfo(res0);
  80. -close(sock);
  81. +closesocket(sock);
  82.  return(SOCKET_ERROR);
  83.  }
  84.  
  85. @@ -1065,7 +1064,7 @@ if(wait > 0)
  86.          {
  87.          if((elapsed = wait_ready(sock, wait, READY_READ)) <= 0)
  88.                  {
  89. -                close(sock);
  90. +                closesocket(sock);
  91.                  if(elapsed == 0) return(netError(ERR_INET_TIMEOUT));
  92.                  else netError(ERR_INET_SELECT_FAILED);
  93.                  }
  94. @@ -1169,7 +1168,7 @@ else
  95.      bytesSent = sendto((int)sock, buffer, size, NO_FLAGS_SET,
  96.          (struct sockaddr *)destination, destination_len);
  97.  
  98. -if(type == SEND_TO_UDP) close((int)sock);
  99. +if(type == SEND_TO_UDP) closesocket((int)sock);
  100.  
  101.  if(bytesSent == SOCKET_ERROR)
  102.          return(netError(ERR_INET_WRITE));
  103. @@ -1271,14 +1270,14 @@ if(bind(sock, (struct sockaddr *)&local_sun, sizeof(struct sockaddr_un)) == -1)
  104.  if(bind(sock, (struct sockaddr *)&local_sun, SUN_LEN(&local_sun)) != 0)
  105.  #endif
  106.      {
  107. -    close(sock);
  108. +    closesocket(sock);
  109.      netErrorIdx = ERR_INET_CANNOT_BIND;
  110.      return(SOCKET_ERROR);
  111.      }
  112.  
  113.  if(listen(sock, MAX_PENDING_CONNECTS) == SOCKET_ERROR)
  114.      {
  115. -    close(sock);
  116. +    closesocket(sock);
  117.      netErrorIdx = ERR_INET_LISTEN_FAILED;
  118.      return(SOCKET_ERROR);
  119.      }
  120. @@ -1318,7 +1317,7 @@ setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const void*)&one, sizeof(one));
  121.  
  122.  if(bind(sock, (struct sockaddr *)local, local_len) == SOCKET_ERROR)
  123.      {
  124. -    close(sock);
  125. +    closesocket(sock);
  126.      netErrorIdx = ERR_INET_CANNOT_BIND;
  127.      return(SOCKET_ERROR);
  128.      }
  129. @@ -1340,7 +1339,7 @@ if(stype == SOCK_STREAM)
  130.      {
  131.      if(listen(sock, MAX_PENDING_CONNECTS) == SOCKET_ERROR)  
  132.          {
  133. -        close(sock);
  134. +        closesocket(sock);
  135.          netErrorIdx = ERR_INET_LISTEN_FAILED;
  136.          return(SOCKET_ERROR);
  137.          }
  138. @@ -1660,7 +1659,7 @@ if( sendall(sock, "[cmd]\n", 6)  == SOCKET_ERROR ||
  139.      sendall(sock, prog, size) == SOCKET_ERROR ||
  140.      sendall(sock, "(exit)\n[/cmd]\n", 14) == SOCKET_ERROR )
  141.      {
  142. -    close(sock);
  143. +    closesocket(sock);
  144.      session->result = netEvalError(ERR_INET_WRITE);
  145.      goto CONTINUE_CREATE_SESSION;
  146.      }
  147. @@ -2433,7 +2432,7 @@ return(fPtr);
  148.  int win32_fclose(FILE * fPtr)
  149.  {
  150.  if(IOchannelIsSocketStream)
  151. -   return(close(getSocket(fPtr)));
  152. +   return(closesocket(getSocket(fPtr)));
  153.  
  154.  return(fclose(fPtr));
  155.  }
  156. @@ -2450,7 +2449,7 @@ pSize = strlen(buffer);
  157.  
  158.  if((pSize = sendall(getSocket(fPtr), buffer, pSize)) == SOCKET_ERROR)
  159.       {
  160. -     close(getSocket(fPtr));
  161. +     closesocket(getSocket(fPtr));
  162.       return(-1);
  163.       }
  164.  
  165. @@ -2466,7 +2465,7 @@ if(!IOchannelIsSocketStream)
  166.  
  167.  if(recv(getSocket(fPtr), &chr, 1, NO_FLAGS_SET) <= 0)
  168.      {
  169. -    close(getSocket(fPtr));
  170. +    closesocket(getSocket(fPtr));
  171.      return(-1);
  172.      }
  173.  
  174. @@ -2486,7 +2485,7 @@ while(bytesReceived < size)
  175.      {
  176.      if(recv(getSocket(fPtr), &chr, 1, NO_FLAGS_SET) <= 0)
  177.          {
  178. -        close(getSocket(fPtr));
  179. +        closesocket(getSocket(fPtr));
  180.          return(NULL);
  181.          }
  182.  
  183. diff --git a/nl-web.c b/nl-web.c
  184. index 518fca0..50f421c 100644
  185. --- a/nl-web.c
  186. +++ b/nl-web.c
  187. @@ -37,10 +37,10 @@
  188.  #define BUFFSIZE 10240
  189.  
  190.  #ifndef WINDOWS
  191. +#define closesocket(s) close(s)
  192.  #define SOCKET_ERROR -1
  193.  #else
  194.  #define fgets win32_fgets
  195. -#define close closesocket
  196.  #endif
  197.  
  198.  /* from nl-sock.c */
  199. @@ -407,7 +407,7 @@ gettimeofday(&socketStart, NULL);
  200.  /* connect to host */
  201.  CONNECT_TO_HOST:
  202.  if(sock)
  203. -    close(sock);
  204. +    closesocket(sock);
  205.  
  206.  
  207.  if((sock = netConnect(pHost, pPort, SOCK_STREAM, NULL, timeout)) == SOCKET_ERROR)
  208. @@ -459,7 +459,7 @@ else /* HTTP_GET, HTTP_DELETE */
  209.  
  210.  if(setjmp(socketTimeoutJump) != 0)
  211.      {
  212. -    if(sock) close(sock);
  213. +    if(sock) closesocket(sock);
  214.      if(resultPtr != NULL) free(resultPtr);
  215.      return(webError(ERR_INET_TIMEOUT));
  216.      }
  217. @@ -643,7 +643,7 @@ else
  218.      result->aux = resultSize + 1;
  219.      }
  220.  
  221. -close(sock);
  222. +closesocket(sock);
  223.  
  224.  if(listFlag)
  225.      {
  226. @@ -1016,7 +1016,7 @@ IOchannel = NULL;
  227.  if(IOchannel != NULL && IOchannelIsSocketStream)
  228.      {
  229.      sendall(getSocket(IOchannel), content, size);
  230. -    close(getSocket(IOchannel));
  231. +    closesocket(getSocket(IOchannel));
  232.      }
  233.  else
  234.      varPrintf(OUT_CONSOLE, "%s", content);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top