Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Diff of /contrib/sockets/sockets.lisp [c020d3] .. [5f4c7e] Maximize Restore

  Switch to side-by-side view

--- a/contrib/sockets/sockets.lisp
+++ b/contrib/sockets/sockets.lisp
@@ -25,6 +25,7 @@
  "#include <sys/types.h>"
  "#include <sys/socket.h>"
  "#include <sys/un.h>"
+ "#define wincoerce(t,x) (x)"
  #-:win32
  "#include <sys/time.h>"
  "#include <netdb.h>"
@@ -52,6 +53,7 @@
 (clines
  "#include <winsock2.h>"
  "typedef unsigned int uint32_t;"
+ "#define wincoerce(t,x) ((t)(x))"
  #-:mingw32
  "typedef int ssize_t;"
  "typedef int socklen_t;"
@@ -228,7 +230,7 @@
 	vector[2] = fixint(ecl_aref(#0,2));
 	vector[3] = fixint(ecl_aref(#0,3));
 	ecl_disable_interrupts();
-	hostent = gethostbyaddr(vector,4,AF_INET);
+	hostent = gethostbyaddr(wincoerce(const char *, vector),4,AF_INET);
 	ecl_enable_interrupts();
 
 	if (hostent != NULL) {
@@ -481,7 +483,7 @@
 	ssize_t len;
 
         ecl_disable_interrupts();
-        len = recvfrom(#0, safe_buffer_pointer(#1, #2),
+        len = recvfrom(#0, wincoerce(char*, safe_buffer_pointer(#1, #2)),
                        #2, flags, NULL,NULL);
 	ecl_enable_interrupts();
         if (len >= 0) {
@@ -754,10 +756,12 @@
 ##if (MSG_NOSIGNAL == 0) && defined(SO_NOSIGPIPE)
 	{
 		int sockopt = #c;
-		setsockopt(#0,SOL_SOCKET,SO_NOSIGPIPE,&sockopt,sizeof(int));
+		setsockopt(#0,SOL_SOCKET,SO_NOSIGPIPE,
+			   wincoerce(char *,&sockopt),
+			   sizeof(int));
 	}
 ##endif
-        len = sendto(sock, buffer,
+        len = sendto(sock, wincoerce(char *,buffer),
                      length, flags,(struct sockaddr*)&sockaddr, 
                      sizeof(struct sockaddr_in));
 	ecl_enable_interrupts();
@@ -787,10 +791,12 @@
 ##if (MSG_NOSIGNAL == 0) && defined(SO_NOSIGPIPE)
 	{
 		int sockopt = #7;
-		setsockopt(#0,SOL_SOCKET,SO_NOSIGPIPE,&sockopt,sizeof(int));
+		setsockopt(#0,SOL_SOCKET,SO_NOSIGPIPE,
+			   wincoerce(char *,&sockopt),
+			   sizeof(int));
 	}
 ##endif
-	len = send(sock, buffer, length, flags);
+	len = send(sock, wincoerce(char *, buffer), length, flags);
 	ecl_enable_interrupts();
         @(return) = len;
 }
@@ -1028,7 +1034,7 @@
 	if (hnd == INVALID_HANDLE_VALUE)
 		@(return) = -1;
 	else
-		@(return) = _open_osfhandle(hnd, O_RDWR);
+		@(return) = _open_osfhandle((intptr_t)hnd, O_RDWR);
 }")))
     (when (= hnd -1)
       (socket-error "CreateNamedPipe"))
@@ -1040,7 +1046,7 @@
          (afd (c-inline (fd) (:int) :int
 	                "
 {
-	HANDLE hnd = _get_osfhandle(#0), dupHnd;
+	HANDLE hnd = (HANDLE)_get_osfhandle(#0), dupHnd;
 	ecl_disable_interrupts();
 	if (ConnectNamedPipe(hnd, NULL) != 0 || GetLastError() == ERROR_PIPE_CONNECTED) {
 		@(return) = #0;
@@ -1085,7 +1091,7 @@
 	if (hnd == INVALID_HANDLE_VALUE)
 		@(return) = -1;
 	else
-		@(return) = _open_osfhandle(hnd, O_RDWR);
+		@(return) = _open_osfhandle((intptr_t)hnd, O_RDWR);
 	ecl_enable_interrupts();
 }")))
 	(socket-error "connect")
@@ -1101,8 +1107,9 @@
                      "
 {
 	DWORD mode = PIPE_READMODE_BYTE | (#1 == ECL_T ? PIPE_NOWAIT : PIPE_WAIT);
-	ecl_disable_interrupts();
-	@(return) = SetNamedPipeHandleState(_get_osfhandle(#0), &mode, NULL, NULL);
+	HANDLE h = (HANDLE)_get_osfhandle(#0);
+	ecl_disable_interrupts();
+	@(return) = SetNamedPipeHandleState(h, &mode, NULL, NULL);
 	ecl_enable_interrupts();
 }"
                      :one-liner nil))
@@ -1115,10 +1122,11 @@
                   "
 {
 	DWORD flags;
-	ecl_disable_interrupts();
-	if (!GetNamedPipeInfo(_get_osfhandle(#0), &flags, NULL, NULL, NULL))
+	HANDLE h = (HANDLE)_get_osfhandle(#0);
+	ecl_disable_interrupts();
+	if (!GetNamedPipeInfo(h, &flags, NULL, NULL, NULL))
 		@(return) = ECL_NIL;
-	if (flags == PIPE_CLIENT_END || DisconnectNamedPipe(_get_osfhandle(#0)))
+	if (flags == PIPE_CLIENT_END || DisconnectNamedPipe(h))
 		@(return) = ECL_T;
 	else
 		@(return) = ECL_NIL;
@@ -1470,7 +1478,7 @@
         socklen_t socklen = sizeof(int);
 
 	ecl_disable_interrupts();
-	ret = getsockopt(#0,#1,#2,&sockopt,&socklen);
+	ret = getsockopt(#0,#1,#2,wincoerce(char*,&sockopt),&socklen);
 	ecl_enable_interrupts();
 
         @(return) = (ret == 0) ? ecl_make_integer(sockopt) : ECL_NIL;
@@ -1486,7 +1494,7 @@
         socklen_t socklen = sizeof(int);
 
 	ecl_disable_interrupts();
-        ret = getsockopt(#0,#1,#2,&sockopt,&socklen);
+	ret = getsockopt(#0,#1,#2,wincoerce(char*,&sockopt),&socklen);
 	ecl_enable_interrupts();
 
         @(return) = (ret == 0) ? ecl_make_integer(sockopt) : ECL_NIL;
@@ -1508,7 +1516,7 @@
         int ret;
 
 	ecl_disable_interrupts();
-	ret = getsockopt(#0,#1,#2,&tv,&socklen);
+	ret = getsockopt(#0,#1,#2,wincoerce(char*,&tv),&socklen);
 	ecl_enable_interrupts();
 
         @(return) = (ret == 0) ? ecl_make_doublefloat((double)tv.tv_sec
@@ -1526,7 +1534,7 @@
 	int ret;
 
 	ecl_disable_interrupts();
-	ret = getsockopt(#0,#1,#2,&sockopt,&socklen);
+	ret = getsockopt(#0,#1,#2,wincoerce(char*,&sockopt),&socklen);
 	ecl_enable_interrupts();
 
 	@(return) = (ret == 0) ? ecl_make_integer((sockopt.l_onoff != 0) ? sockopt.l_linger : 0) : ECL_NIL;
@@ -1542,7 +1550,7 @@
         int ret;
 
 	ecl_disable_interrupts();
-	ret = setsockopt(#0,#1,#2,&sockopt,sizeof(int));
+	ret = setsockopt(#0,#1,#2,wincoerce(char *,&sockopt),sizeof(int));
 	ecl_enable_interrupts();
 
         @(return) = (ret == 0) ? ECL_T : ECL_NIL;
@@ -1558,7 +1566,7 @@
         int ret;
 
 	ecl_disable_interrupts();
-	ret = setsockopt(#0,#1,#2,&sockopt,sizeof(int));
+	ret = setsockopt(#0,#1,#2,wincoerce(char *,&sockopt),sizeof(int));
 	ecl_enable_interrupts();
 
         @(return) = (ret == 0) ? ECL_T : ECL_NIL;
@@ -1604,7 +1612,8 @@
 	}
 
 	ecl_disable_interrupts();
-	ret = setsockopt(#0,#1,#2,&sockopt,sizeof(struct linger));
+	ret = setsockopt(#0,#1,#2,wincoerce(char *,&sockopt),
+			 sizeof(struct linger));
 	ecl_enable_interrupts();
 
 	@(return) = (ret == 0) ? ECL_T : ECL_NIL;