[PATCH 09 of 14 RFC c-hglib:level0] hg_rawwrite: write a buffer to command server for the given handle
Iulian Stana
julian.stana at gmail.com
Tue Sep 3 15:30:48 CDT 2013
# HG changeset patch
# User Iulian Stana <julian.stana at gmail.com>
# Date 1378235626 -10800
# Tue Sep 03 22:13:46 2013 +0300
# Node ID 555015b8d91225388caf7e404837521a0b7bdf1f
# Parent 41b2f0094c3a6257d4f18cbeb9962ba743c1aff6
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
@@ -301,3 +301,31 @@
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->next_header.length;
+ 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;
+ }
+
+ if(read_header(handle) < 0){
+ return -1;
+ }
+ return length;
+}
diff --git a/client.h b/client.h
--- a/client.h
+++ b/client.h
@@ -118,4 +118,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