Patchwork [c-hglib] hg_rawread: reading some unparse data from command server

login
register
mail settings
Submitter Iulian Stana
Date Sept. 18, 2013, 10:20 p.m.
Message ID <54a75470cc4a33a6a92c.1379542822@doppler>
Download mbox | patch
Permalink /patch/2531/
State Accepted
Headers show

Comments

Iulian Stana - Sept. 18, 2013, 10:20 p.m.
# HG changeset patch
# User Iulian Stana <julian.stana@gmail.com>
# Date 1379453713 -10800
#      Wed Sep 18 00:35:13 2013 +0300
# Node ID 54a75470cc4a33a6a92c71e6dd2bb81572b9c1e6
# Parent  56adaa5609236d29884eab4c1a1799a2692d3306
hg_rawread: reading some unparse data from command server

Will read the data found in the pipe. This function will read min(sizebuff,
bytes_on_pipe).
Users can provide a buffer with a bigger size than the bytes found on the pipe,
you don't want to read more bytes then it must.
Matt Mackall - Sept. 18, 2013, 10:42 p.m.
On Thu, 2013-09-19 at 01:20 +0300, Iulian Stana wrote:
> # HG changeset patch
> # User Iulian Stana <julian.stana@gmail.com>
> # Date 1379453713 -10800
> #      Wed Sep 18 00:35:13 2013 +0300
> # Node ID 54a75470cc4a33a6a92c71e6dd2bb81572b9c1e6
> # Parent  56adaa5609236d29884eab4c1a1799a2692d3306
> hg_rawread: reading some unparse data from command server

Queued, thanks. No check-code complaints!

Patch

diff --git a/hglib/client.c b/hglib/client.c
--- a/hglib/client.c
+++ b/hglib/client.c
@@ -238,4 +238,34 @@ 
 	return 0;
 }
 
+/*
+ * Reading some unparse data from the server.
+ * */
+int hg_rawread(hg_handle *handle, char *buffer, size_t sizebuff)
+{
+	int length = handle->bytes_on_pipe;
+	hg_header *ch = handle->header;
 
+	if (!handle) {
+		errno = EINVAL;
+		return -1;
+	}
+
+	/* If the current channel is not an input channel return 0. */
+	if (!(ch->channel == o || ch->channel == e)) {
+		return 0;
+	}
+
+	length = (length > sizebuff)? sizebuff : length;
+
+	if (read(handle->p_read, buffer, length) < 0) {
+		return -1;
+	}
+
+	buffer[length] = '\0';
+	handle->bytes_on_pipe -= length;
+
+	return length;
+}
+
+