Comments
Patch
@@ -231,3 +231,32 @@
free(cmd_send);
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;
+}
@@ -154,4 +154,22 @@
* */
int hg_rawcommand(hg_handle *handle, char *const command[]);
+/**
+ * \brief Reading some unparse data from the server.
+ *
+ * Will read just a 'line', the header that is received from server and the
+ * data that comes after the header
+ * \param handle The handle of the connection, wherewith I want to communicate
+ * \param buffer A character array where the read content will be stored.
+ * \param sizebuff The number of bytes to read.
+ * \retval Number the number of bytes that were read.
+ * \retval -1 to indicate an error, with errno set appropriately.
+ *
+ * errno can be:
+ * - EINVAL - Invalid argument (handle it's set to a null pointer)
+ * - read(2) command errors
+ * */
+int hg_rawread(hg_handle *handle, char *buffer, size_t sizebuff);
+
+
#endif