[PATCH c-hglib] hg_rawwrite: write a buffer to command server for the given handle

Iulian Stana julian.stana at gmail.com
Wed Sep 18 17:47:19 CDT 2013


# HG changeset patch
# User Iulian Stana <julian.stana at gmail.com>
# Date 1379453894 -10800
#      Wed Sep 18 00:38:14 2013 +0300
# Node ID 8bdb422f21775a3826a59eeefd17e3f6da6a0308
# Parent  54a75470cc4a33a6a92c71e6dd2bb81572b9c1e6
hg_rawwrite: write a buffer to command server for the given handle

This function will be used when one of the input channels will be received
from the command server. ('I' or 'L' channels).

diff --git a/hglib/client.c b/hglib/client.c
--- a/hglib/client.c
+++ b/hglib/client.c
@@ -268,4 +268,30 @@
 	return length;
 }
 
+/*
+ * Will write the buffer to the server.
+ * */
+int hg_rawwrite(hg_handle *handle, const char *buffer, size_t buff_size)
+{
+	int length = handle->bytes_on_pipe;
+	uint32_t swap_size;
 
+	if (!handle) {
+		errno = EINVAL;
+		return -1;
+	}
+
+	length = (length > buff_size)? buff_size : length;
+	swap_size = swap_uint32(length);
+
+	if (write(handle->p_write, &swap_size, sizeof(uint32_t)) < 0) {
+		return -1;
+	}
+	if (write(handle->p_write, buffer, length) < 0) {
+		return -1;
+	}
+
+	handle->bytes_on_pipe = 0;
+	return length;
+}
+


More information about the Mercurial-devel mailing list