Patchwork [4,of,6,RFC,hglib] trash_data: this function will consume the data received from cmdserver

login
register
mail settings
Submitter Iulian Stana
Date Sept. 5, 2013, 2:13 p.m.
Message ID <17d04670c65d6e6653a7.1378390404@doppler>
Download mbox | patch
Permalink /patch/2336/
State Deferred, archived
Headers show

Comments

Iulian Stana - Sept. 5, 2013, 2:13 p.m.
# HG changeset patch
# User Iulian Stana <julian.stana@gmail.com>
# Date 1378388950 -10800
#      Thu Sep 05 16:49:10 2013 +0300
# Node ID 17d04670c65d6e6653a7a3c7875f2918abe073c3
# Parent  470eea41ab3e0f4756339c3cc9f1563361224787
trash_data: this function will consume the data received from cmdserver

This function it's a trash, the output data will be thrown away and the error
data will be passed to callback function if a callback function is set.

Patch

diff --git a/client.c b/client.c
--- a/client.c
+++ b/client.c
@@ -70,3 +70,38 @@ 
 	return 0;
 }
 
+/** 
+ * This function will be called only if an error occur on hg_fetch_cset_entry 
+ * function. In case of any error, this function will consume the entire data 
+ * received from cmdserver and will end the current command.
+ *
+ * if there is any error, read everything from pipe:
+ *    pass error data to callback function
+ *    trash the output data
+ *    read the exticode 
+ *    return exitcode;
+ **/
+int trash_data(hg_handle *handle, int(*callback)(const char *msg, size_t len))
+{
+	char buff[4096];
+	int nb;
+	int exitcode;
+	while(hg_next_channel(handle) != 'r'){
+		/* output channels 'o', 'e' channels */
+		while(nb = hg_rawread(handle, buff, 4096), 
+				nb > 0){
+			/* trash output data. */
+			if(hg_current_channel(handle) == 'o'){
+			}
+			/* handle error data. */
+			else if(hg_current_channel(handle) == 'e'){
+				if(callback)
+					callback(buff, strlen(buff));
+			}
+		}
+	}
+	if(hg_next_channel(handle) == 'r'){
+		exitcode = hg_exitcode(handle);
+	}
+	return exitcode;
+}