[PATCH 09 of 11 c-hglib:level0 V2] hg_rawwrite: write a buffer to command server for the given handle
Iulian Stana
julian.stana at gmail.com
Fri Sep 13 15:31:59 CDT 2013
# HG changeset patch
# User Iulian Stana <julian.stana at gmail.com>
# Date 1379103684 -10800
# Fri Sep 13 23:21:24 2013 +0300
# Node ID cae0e15b9169080f054f3087b1dd6e44c419969c
# Parent fd9e45f6995d55def8e6c961c5e91e698ce19184
hg_rawwrite: write a buffer to command server for the given handle
diff --git a/client.c b/client.c
--- a/client.c
+++ b/client.c
@@ -260,3 +260,30 @@
return length;
}
+
+/*
+ * Will write the buffer to the server.
+ * */
+int hg_rawwrite(hg_handle *handle, const char *buffer, size_t buff_size)
+{
+ int length = handle->bytes_on_pipe;
+ uint32_t swap_size;
+
+ if(!handle) {
+ errno = EINVAL;
+ return -1;
+ }
+ length = (length > buff_size)? buff_size : length;
+ swap_size = swap_uint32(length);
+
+ if(write(handle->p_write, &swap_size, sizeof(uint32_t)) < 0){
+ return -1;
+ }
+ if(write(handle->p_write, buffer, length) < 0){
+ return -1;
+ }
+
+ handle->bytes_on_pipe = 0;
+ return length;
+}
+
diff --git a/client.h b/client.h
--- a/client.h
+++ b/client.h
@@ -171,5 +171,22 @@
* */
int hg_rawread(hg_handle *handle, char *buffer, size_t sizebuff);
+/**
+ * \brief Will write the buffer to server for the connection establish by the
+ * handle.
+ *
+ * This function will be used when one of the input channels will be received
+ * from the command server. ('I' or 'L' channels)
+ * \param handle The handle of the connection, wherewith I want to communicate
+ * \param buffer A null terminated character string of the content to write.
+ * \param sizebuff The number of bytes to write
+ * \retval Number the number of bytes that were written
+ * \retval -1 to indicate an error, with errno set appropriately.
+ *
+ * errno can be:
+ * - EINVAL - Invalid argument (handle it's set to a null pointer)
+ * - write(2) command errors
+ * */
+int hg_rawwrite(hg_handle *handle, const char *buffer, size_t sizebuff);
#endif
More information about the Mercurial-devel
mailing list