summaryrefslogtreecommitdiff
path: root/src/transport-http.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <carlos@cmartin.tk>2011-09-30 17:21:30 +0200
committerCarlos Martín Nieto <carlos@cmartin.tk>2011-10-01 00:41:08 +0200
commitccc9872d4df7ca6cd44f777c0600c4b1fab0f9e6 (patch)
tree9deaa2ef455a51142bc2f0e831c8e718932cdcd6 /src/transport-http.c
parenta95aeb489f32fa7e570ecad12fc236f0a0e237a3 (diff)
downloadlibgit2-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/transport-http.c')
-rw-r--r--src/transport-http.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/transport-http.c b/src/transport-http.c
index 70086adea..3ee4025f8 100644
--- a/src/transport-http.c
+++ b/src/transport-http.c
@@ -52,6 +52,9 @@ typedef struct {
enum last_cb last_cb;
char *content_type;
char *service;
+#ifdef GIT_WIN32
+ WSADATA wsd;
+#endif
} transport_http;
static int gen_request(git_buf *buf, const char *url, const char *host, const char *service)
@@ -76,7 +79,8 @@ static int gen_request(git_buf *buf, const char *url, const char *host, const ch
static int do_connect(transport_http *t, const char *service)
{
git_buf request = GIT_BUF_INIT;
- int s = -1, error;
+ int error;
+ int s;
const char *url, *prefix;
char *host = NULL, *port = NULL;
@@ -362,6 +366,10 @@ static int http_close(git_transport *transport)
if (error < 0)
return git__throw(GIT_EOSERR, "Failed to close the socket: %s", strerror(errno));
+#ifdef GIT_WIN32
+ WSACleanup();
+#endif
+
return GIT_SUCCESS;
}
@@ -388,6 +396,9 @@ static void http_free(git_transport *transport)
int git_transport_http(git_transport **out)
{
transport_http *t;
+#ifdef GIT_WIN32
+ int ret;
+#endif
t = git__malloc(sizeof(transport_http));
if (t == NULL)
@@ -402,5 +413,13 @@ int git_transport_http(git_transport **out)
*out = (git_transport *) t;
+#ifdef GIT_WIN32
+ ret = WSAStartup(MAKEWORD(2,2), &t->wsd);
+ if (ret != 0) {
+ http_free(*out);
+ return git__throw(GIT_EOSERR, "Winsock init failed");
+ }
+#endif
+
return GIT_SUCCESS;
}