From patchwork Fri Sep 13 20:31:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [08, of, 11, c-hglib:level0, V2] hg_rawread: reading some unparse data from command server From: Iulian Stana X-Patchwork-Id: 2441 Message-Id: To: mercurial-devel@selenic.com Date: Fri, 13 Sep 2013 23:31:58 +0300 # HG changeset patch # User Iulian Stana # Date 1379103635 -10800 # Fri Sep 13 23:20:35 2013 +0300 # Node ID fd9e45f6995d55def8e6c961c5e91e698ce19184 # Parent 4a3e55c42250a8efa86cd1ce83bfee48fbc10378 hg_rawread: reading some unparse data from command server diff --git a/client.c b/client.c --- a/client.c +++ b/client.c @@ -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; +} diff --git a/client.h b/client.h --- a/client.h +++ b/client.h @@ -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