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>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
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) {