Implement and use gitno_send
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
diff --git a/src/netops.c b/src/netops.c
index 04f758f..532d0d3 100644
--- a/src/netops.c
+++ b/src/netops.c
@@ -23,9 +23,15 @@
* Boston, MA 02110-1301, USA.
*/
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
+#ifndef _MSC_VER
+# include <sys/types.h>
+# include <sys/socket.h>
+# include <netdb.h>
+#else
+# include <winsock2.h>
+# include <Ws2tcpip.h>
+# pragma comment(lib, "Ws2_32.lib")
+#endif
#include "git2/errors.h"
@@ -74,3 +80,18 @@ cleanup:
freeaddrinfo(info);
return error;
}
+
+int gitno_send(int s, const char *msg, int len, int flags)
+{
+ int ret, off = 0;
+
+ while (off < len) {
+ ret = send(s, msg + off, len - off, flags);
+ if (ret < 0)
+ return GIT_EOSERR;
+
+ off += ret;
+ }
+
+ return off;
+}
diff --git a/src/netops.h b/src/netops.h
index 10627d4..620fb12 100644
--- a/src/netops.h
+++ b/src/netops.h
@@ -5,5 +5,6 @@
#define INCLUDE_netops_h__
int gitno_connect(const char *host, const char *port);
+int gitno_send(int s, const char *msg, int len, int flags);
#endif
diff --git a/src/transport_git.c b/src/transport_git.c
index 12af21b..063f382 100644
--- a/src/transport_git.c
+++ b/src/transport_git.c
@@ -91,7 +91,7 @@ static int do_connect(git_priv *priv, const char *url)
int s = -1;
char *host, *port, *msg;
const char prefix[] = "git://";
- int error, ret, msg_len, connected = 0;
+ int error, msg_len, connected = 0;
if (!git__prefixcmp(url, prefix))
url += STRLEN(prefix);
@@ -104,13 +104,10 @@ static int do_connect(git_priv *priv, const char *url)
if (error < GIT_SUCCESS)
goto cleanup;
- /* FIXME: Do this in a loop */
- ret = send(s, msg, msg_len, 0);
+ error = gitno_send(s, msg, msg_len, 0);
free(msg);
- if (ret < 0) {
- error = git__throw(GIT_EOSERR, "Failed to send request");
+ if (error < GIT_SUCCESS)
goto cleanup;
- }
priv->socket = s;