diff options
author | Carlos Martín Nieto <carlos@cmartin.tk> | 2011-08-19 09:03:19 +0200 |
---|---|---|
committer | Vicent Marti <tanoku@gmail.com> | 2011-08-30 19:37:14 +0200 |
commit | 74bd343ae83398c7e00c239aea1ff8525dc958a1 (patch) | |
tree | ecf99df643631ed691195629b930177c2fb00eb9 | |
parent | f978b748bb50beb0ccbebc3aa118ad289e4c9cba (diff) | |
download | libgit2-74bd343ae83398c7e00c239aea1ff8525dc958a1.tar.gz |
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>
-rw-r--r-- | src/netops.c | 16 | ||||
-rw-r--r-- | src/netops.h | 9 | ||||
-rw-r--r-- | 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 <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 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 <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) { |