diff options
| author | Carlos Martín Nieto <carlos@cmartin.tk> | 2011-09-30 17:21:30 +0200 |
|---|---|---|
| committer | Carlos Martín Nieto <carlos@cmartin.tk> | 2011-10-01 00:41:08 +0200 |
| commit | ccc9872d4df7ca6cd44f777c0600c4b1fab0f9e6 (patch) | |
| tree | 9deaa2ef455a51142bc2f0e831c8e718932cdcd6 /src/netops.c | |
| parent | a95aeb489f32fa7e570ecad12fc236f0a0e237a3 (diff) | |
| download | libgit2-ccc9872d4df7ca6cd44f777c0600c4b1fab0f9e6.tar.gz | |
Initialise the winsock DLL
Windows wants us to initialise the networking DLL before we're allowed
to send data through a socket. Call WSASetup and WSACleanup if
GIT_WIN32 is defined.
Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Diffstat (limited to 'src/netops.c')
| -rw-r--r-- | src/netops.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/netops.c b/src/netops.c index 54aaa4677..c8fe37645 100644 --- a/src/netops.c +++ b/src/netops.c @@ -77,7 +77,7 @@ int gitno_connect(const char *host, const char *port) struct addrinfo *info, *p; struct addrinfo hints; int ret, error = GIT_SUCCESS; - int s; + GIT_SOCKET s; memset(&hints, 0x0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; @@ -92,7 +92,11 @@ int gitno_connect(const char *host, const char *port) for (p = info; p != NULL; p = p->ai_next) { s = socket(p->ai_family, p->ai_socktype, p->ai_protocol); +#ifdef GIT_WIN32 + if (s == INVALID_SOCKET) { +#else if (s < 0) { +#endif error = GIT_EOSERR; goto cleanup; } @@ -109,19 +113,21 @@ int gitno_connect(const char *host, const char *port) } /* Oops, we couldn't connect to any address */ - error = GIT_EOSERR; + error = git__throw(GIT_EOSERR, "Failed to connect: %s", strerror(errno)); cleanup: freeaddrinfo(info); return error; } -int gitno_send(int s, const char *msg, size_t len, int flags) +int gitno_send(GIT_SOCKET s, const char *msg, size_t len, int flags) { int ret; size_t off = 0; while (off < len) { + errno = 0; + ret = send(s, msg + off, len - off, flags); if (ret < 0) return git__throw(GIT_EOSERR, "Error sending data: %s", strerror(errno)); |
