Commit 74bd343ae83398c7e00c239aea1ff8525dc958a1

Carlos Martín Nieto 2011-08-19T09:03:19

Fix Windows compilation Sockets on Windows are unsigned, so define a type GIT_SOCKET which is signed or unsigned depending on the platform. Thanks to Em for his patience with this. Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>

diff --git a/src/netops.c b/src/netops.c
index 8126bce..7291ba6 100644
--- a/src/netops.c
+++ b/src/netops.c
@@ -26,6 +26,7 @@
 #ifndef _WIN32
 # include <sys/types.h>
 # include <sys/socket.h>
+# include <sys/select.h>
 # include <netdb.h>
 #else
 # define _WIN32_WINNT 0x0501
@@ -143,3 +144,18 @@ int gitno_send(int s, const char *msg, int len, int flags)
 
 	return off;
 }
+
+int gitno_select_in(gitno_buffer *buf, long int sec, long int usec)
+{
+	fd_set fds;
+	struct timeval tv;
+
+	tv.tv_sec = sec;
+	tv.tv_usec = usec;
+
+	FD_ZERO(&fds);
+	FD_SET(buf->fd, &fds);
+
+	/* The select(2) interface is silly */
+	return select(buf->fd + 1, &fds, NULL, NULL, &tv);
+}
diff --git a/src/netops.h b/src/netops.h
index c828ed9..d18116f 100644
--- a/src/netops.h
+++ b/src/netops.h
@@ -4,11 +4,17 @@
 #ifndef INCLUDE_netops_h__
 #define INCLUDE_netops_h__
 
+#ifndef _WIN32
+typedef int GIT_SOCKET;
+#else
+typedef unsigned int GIT_SOCKET;
+#endif
+
 typedef struct gitno_buffer {
 	char *data;
 	unsigned int len;
 	unsigned int offset;
-	int fd;
+	GIT_SOCKET fd;
 } gitno_buffer;
 
 void gitno_buffer_setup(gitno_buffer *buf, char *data, unsigned int len, int fd);
@@ -18,5 +24,6 @@ void gitno_consume_n(gitno_buffer *buf, unsigned int cons);
 
 int gitno_connect(const char *host, const char *port);
 int gitno_send(int s, const char *msg, int len, int flags);
+int gitno_select_in(gitno_buffer *buf, long int sec, long int usec);
 
 #endif
diff --git a/src/transport_git.c b/src/transport_git.c
index 0eec39d..7b0edcf 100644
--- a/src/transport_git.c
+++ b/src/transport_git.c
@@ -23,10 +23,6 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef __MINGW32__
-#include <sys/select.h>
-#endif
-
 #include "git2/net.h"
 #include "git2/common.h"
 #include "git2/types.h"
@@ -394,16 +390,8 @@ static int git_negotiate_fetch(git_transport *transport, git_repository *repo, g
 			git_pkt *pkt;
 			git_pkt_send_flush(t->socket);
 			while (1) {
-				fd_set fds;
-				struct timeval tv;
-
-				FD_ZERO(&fds);
-				FD_SET(t->socket, &fds);
-				tv.tv_sec = 1; /* Wait for max. 1 second */
-				tv.tv_usec = 0;
-
-				/* The select(2) interface is silly */
-				error = select(t->socket + 1, &fds, NULL, NULL, &tv);
+				/* Wait for max. 1 second */
+				error = gitno_select_in(&buf, 1, 0);
 				if (error < GIT_SUCCESS) {
 					error = git__throw(GIT_EOSERR, "Error in select");
 				} else if (error == 0) {