Comments
Patch
@@ -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;
+}