summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVicent Martí <tanoku@gmail.com>2012-05-05 16:47:20 -0700
committerVicent Martí <tanoku@gmail.com>2012-05-05 16:47:20 -0700
commitcd58c15c589970765cd46e7bbdaebf6250fd7626 (patch)
treef7f95202e96151b3ac7ea22697e7e60825375268 /src
parent48ecd122ea6fb8cf12fb4029974c314e5d9efb62 (diff)
parent35cdd261f353696181236328323e8d123cad57d4 (diff)
downloadlibgit2-cd58c15c589970765cd46e7bbdaebf6250fd7626.tar.gz
Merge remote-tracking branch 'scottjg/fix-mingw32' into development
Conflicts: src/netops.c src/netops.h src/transports/http.c tests-clar/clar
Diffstat (limited to 'src')
-rw-r--r--src/netops.c11
-rw-r--r--src/netops.h2
-rw-r--r--src/transports/git.c23
-rw-r--r--src/transports/http.c4
-rw-r--r--src/win32/utf-conv.c1
5 files changed, 24 insertions, 17 deletions
diff --git a/src/netops.c b/src/netops.c
index e2fec0b48..2d200002f 100644
--- a/src/netops.c
+++ b/src/netops.c
@@ -93,7 +93,7 @@ void gitno_consume_n(gitno_buffer *buf, size_t cons)
buf->offset -= cons;
}
-GIT_SOCKET gitno_connect(const char *host, const char *port)
+int gitno_connect(GIT_SOCKET *sock, const char *host, const char *port)
{
struct addrinfo *info = NULL, *p;
struct addrinfo hints;
@@ -106,7 +106,7 @@ GIT_SOCKET gitno_connect(const char *host, const char *port)
if ((ret = getaddrinfo(host, port, &hints, &info)) < 0) {
giterr_set(GITERR_NET, "Failed to resolve address for %s: %s", host, gai_strerror(ret));
- return INVALID_SOCKET;
+ return -1;
}
for (p = info; p != NULL; p = p->ai_next) {
@@ -125,11 +125,14 @@ GIT_SOCKET gitno_connect(const char *host, const char *port)
}
/* Oops, we couldn't connect to any address */
- if (s == INVALID_SOCKET && p == NULL)
+ if (s == INVALID_SOCKET && p == NULL) {
giterr_set(GITERR_OS, "Failed to connect to %s", host);
+ return -1;
+ }
freeaddrinfo(info);
- return s;
+ *sock = s;
+ return 0;
}
int gitno_send(GIT_SOCKET s, const char *msg, size_t len, int flags)
diff --git a/src/netops.h b/src/netops.h
index f370019ff..9d13f3891 100644
--- a/src/netops.h
+++ b/src/netops.h
@@ -21,7 +21,7 @@ int gitno_recv(gitno_buffer *buf);
void gitno_consume(gitno_buffer *buf, const char *ptr);
void gitno_consume_n(gitno_buffer *buf, size_t cons);
-GIT_SOCKET gitno_connect(const char *host, const char *port);
+int gitno_connect(GIT_SOCKET *s, const char *host, const char *port);
int gitno_send(GIT_SOCKET s, const char *msg, size_t len, int flags);
int gitno_close(GIT_SOCKET s);
int gitno_send_chunk_size(int s, size_t len);
diff --git a/src/transports/git.c b/src/transports/git.c
index c51b1670f..9eae9a1a2 100644
--- a/src/transports/git.c
+++ b/src/transports/git.c
@@ -100,10 +100,11 @@ cleanup:
*/
static int do_connect(transport_git *t, const char *url)
{
- GIT_SOCKET s;
char *host, *port;
const char prefix[] = "git://";
- int error, connected = 0;
+ int error;
+
+ t->socket = INVALID_SOCKET;
if (!git__prefixcmp(url, prefix))
url += strlen(prefix);
@@ -111,22 +112,24 @@ static int do_connect(transport_git *t, const char *url)
if (gitno_extract_host_and_port(&host, &port, url, GIT_DEFAULT_PORT) < 0)
return -1;
- s = gitno_connect(host, port);
- connected = 1;
- error = send_request(s, NULL, url);
- t->socket = s;
+ if (gitno_connect(&t->socket, host, port) == 0) {
+ error = send_request(t->socket, NULL, url);
+ }
git__free(host);
git__free(port);
- if (error < GIT_SUCCESS && s > 0)
- gitno_close(s);
- if (!connected) {
+ if (error < 0 && t->socket != INVALID_SOCKET) {
+ gitno_close(t->socket);
+ t->socket = INVALID_SOCKET;
+ }
+
+ if (t->socket == INVALID_SOCKET) {
giterr_set(GITERR_NET, "Failed to connect to the host");
return -1;
}
- return error;
+ return 0;
}
/*
diff --git a/src/transports/http.c b/src/transports/http.c
index 1b2b5eb89..bc4a615f1 100644
--- a/src/transports/http.c
+++ b/src/transports/http.c
@@ -85,12 +85,12 @@ static int gen_request(git_buf *buf, const char *url, const char *host, const ch
static int do_connect(transport_http *t, const char *host, const char *port)
{
- GIT_SOCKET s = -1;
+ GIT_SOCKET s;
if (t->parent.connected && http_should_keep_alive(&t->parser))
return 0;
- if ((s = gitno_connect(host, port)) < 0)
+ if (gitno_connect(&s, host, port) < 0)
return -1;
t->socket = s;
diff --git a/src/win32/utf-conv.c b/src/win32/utf-conv.c
index fbcb69d0a..76f1e4237 100644
--- a/src/win32/utf-conv.c
+++ b/src/win32/utf-conv.c
@@ -7,6 +7,7 @@
#include "common.h"
#include "utf-conv.h"
+#include "git2/windows.h"
/*
* Default codepage value