summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <carlos@cmartin.tk>2012-03-16 15:15:21 +0100
committerVicent Martí <tanoku@gmail.com>2012-04-11 19:16:10 +0200
commitbd6585a7f55bb630b69cf2928032616f4afad45b (patch)
tree34508b00b500674dc8c01c03ef3b3fab8c36a8f6
parent56b7df108c6b24fe786325944309a52e79087a52 (diff)
downloadlibgit2-bd6585a7f55bb630b69cf2928032616f4afad45b.tar.gz
netops: show winsock error messages on Windows
-rw-r--r--src/netops.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/netops.c b/src/netops.c
index e69e2ee95..2d759fd58 100644
--- a/src/netops.c
+++ b/src/netops.c
@@ -25,6 +25,26 @@
#include "common.h"
#include "netops.h"
#include "posix.h"
+#include "buffer.h"
+
+#ifdef GIT_WIN32
+static void net_set_error(const char *str)
+{
+ int size, error = WSAGetLastError();
+ LPSTR err_str = NULL;
+
+ size = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+ 0, error, 0, (LPSTR)&err_str, 0, 0);
+
+ giterr_set(GITERR_NET, "%s: $s", str, err_str);
+ LocalFree(err_str);
+}
+#else
+static void net_set_error(const char *str)
+{
+ giterr_set(GITERR_NET, "%s: %s", str, strerror(errno));
+}
+#endif
void gitno_buffer_setup(gitno_buffer *buf, char *data, unsigned int len, int fd)
{
@@ -45,7 +65,7 @@ int gitno_recv(gitno_buffer *buf)
return 0;
if (ret < 0) {
- giterr_set(GITERR_NET, "Error receiving data");
+ net_set_error("Error receiving data");
return -1;
}
@@ -100,7 +120,7 @@ int gitno_connect(const char *host, const char *port)
#else
if (s < 0) {
#endif
- giterr_set(GITERR_OS, "Error creating socket");
+ net_set_error("Error creating socket");
freeaddrinfo(info);
return -1;
}
@@ -132,7 +152,7 @@ int gitno_send(GIT_SOCKET s, const char *msg, size_t len, int flags)
ret = send(s, msg + off, len - off, flags);
if (ret < 0) {
- giterr_set(GITERR_OS, "Error sending data: %s", strerror(errno));
+ net_set_error("Error sending data");
return -1;
}