From 74bd343ae83398c7e00c239aea1ff8525dc958a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Fri, 19 Aug 2011 09:03:19 +0200 Subject: [PATCH] Fix Windows compilation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/netops.c | 16 ++++++++++++++++ src/netops.h | 9 ++++++++- src/transport_git.c | 16 ++-------------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/netops.c b/src/netops.c index 8126bcee3..7291ba639 100644 --- a/src/netops.c +++ b/src/netops.c @@ -26,6 +26,7 @@ #ifndef _WIN32 # include # include +# include # include #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 c828ed9f3..d18116f34 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 0eec39df2..7b0edcfef 100644 --- a/src/transport_git.c +++ b/src/transport_git.c @@ -23,10 +23,6 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __MINGW32__ -#include -#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) {