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

login
register
mail settings
Submitter Iulian Stana
Date Sept. 18, 2013, 10:47 p.m.
Message ID <8bdb422f21775a3826a5.1379544439@doppler>
Download mbox | patch
Permalink /patch/2532/
State Accepted
Headers show

Comments

Iulian Stana - Sept. 18, 2013, 10:47 p.m.
# HG changeset patch
# User Iulian Stana <julian.stana@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).
Matt Mackall - Sept. 18, 2013, 11:15 p.m.
On Thu, 2013-09-19 at 01:47 +0300, Iulian Stana wrote:
> # HG changeset patch
> # User Iulian Stana <julian.stana@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

Queued, thanks.

Patch

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;
+}
+