summaryrefslogtreecommitdiff
path: root/src/netops.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <carlos@cmartin.tk>2011-09-14 00:54:45 +0200
committerVicent Marti <tanoku@gmail.com>2011-10-12 21:33:18 +0200
commit34bfb4b0d40b17e51d25df726a80226ccbc8dec7 (patch)
tree6388a5ce532dde49b09185eab9f883396fa19a41 /src/netops.c
parenteb07a4d1dd5b6ec2ee60566d0ec2aa705bf37f4c (diff)
downloadlibgit2-34bfb4b0d40b17e51d25df726a80226ccbc8dec7.tar.gz
net,pkt: add chunked support
As we don't know the length of the message we want to send to the other end, we send a chunk size before each message. In later versions, sending the wants might benefit from batching the lines together. Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Diffstat (limited to 'src/netops.c')
-rw-r--r--src/netops.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/netops.c b/src/netops.c
index 7d8a7b28c..da242795b 100644
--- a/src/netops.c
+++ b/src/netops.c
@@ -23,6 +23,7 @@
#include "common.h"
#include "netops.h"
+#include "posix.h"
void gitno_buffer_setup(gitno_buffer *buf, char *data, unsigned int len, int fd)
{
@@ -138,6 +139,7 @@ int gitno_send(GIT_SOCKET s, const char *msg, size_t len, int flags)
return off;
}
+
#ifdef GIT_WIN32
int gitno_close(GIT_SOCKET s)
{
@@ -150,6 +152,20 @@ int gitno_close(GIT_SOCKET s)
}
#endif
+int gitno_send_chunk_size(int s, size_t len)
+{
+ char str[8] = {0};
+ int ret;
+
+ ret = p_snprintf(str, sizeof(str), "%zx", len);
+ if (ret >= (int) sizeof(str)) {
+ return git__throw(GIT_ESHORTBUFFER, "Your number is too fucking big");
+ }
+
+ return gitno_send(s, str, ret, 0 /* TODO: MSG_MORE */);
+}
+
+
int gitno_select_in(gitno_buffer *buf, long int sec, long int usec)
{
fd_set fds;