From ce5160a39d26a8e7cf0633d0d144436a5156837a Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 19 Aug 2015 13:37:19 +0200 Subject: put full_send in libmdsserver, clients that only has one socket uses a macro to remove the socket parameter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- doc/info/mds.texinfo | 8 ++++++++ src/libmdsserver/util.c | 25 ++++++++++++++++++++++++ src/libmdsserver/util.h | 12 ++++++++++++ src/mds-clipboard.c | 42 +++++++++++------------------------------ src/mds-clipboard.h | 9 --------- src/mds-colour.c | 42 +++++++++++------------------------------ src/mds-colour.h | 10 ---------- src/mds-echo.c | 42 +++++++++++------------------------------ src/mds-echo.h | 9 --------- src/mds-kkbd.c | 42 +++++++++++------------------------------ src/mds-kkbd.h | 9 --------- src/mds-registry/mds-registry.c | 12 ++++++++++++ src/mds-registry/registry.c | 11 +++++++++++ src/mds-registry/util.c | 31 ------------------------------ src/mds-registry/util.h | 9 --------- src/mds-vt.c | 32 ------------------------------- src/mds-vt.h | 11 ----------- 17 files changed, 112 insertions(+), 244 deletions(-) diff --git a/doc/info/mds.texinfo b/doc/info/mds.texinfo index 902e698..8d44bdb 100644 --- a/doc/info/mds.texinfo +++ b/doc/info/mds.texinfo @@ -6552,6 +6552,14 @@ if not @code{NULL}, the length of the read file is stored in @code{*length}. On success, the read content is retured, on error @code{NULL} is returned. +@item @code{full_send} [(@code{int socket, const char* message, size_t length}) @arrow{} @code{int}] +@fnindex @code{full_send} +@cpindex Message passing +Send the message @code{message}, with the length +@code{length}, to the socket whose file descriptor is +@code{socket} and ignores interruptions. Returns zero on +success and @code{-1} on error. + @item @code{startswith_n} [(@code{const char*, const char*, size_t, size_t}) @arrow{} @code{int}] @fnindex @code{startswith_n} @cpindex String comparison diff --git a/src/libmdsserver/util.c b/src/libmdsserver/util.c index 9160672..eb79bff 100644 --- a/src/libmdsserver/util.c +++ b/src/libmdsserver/util.c @@ -313,6 +313,31 @@ char* full_read(int fd, size_t* length) } +/** + * Send a full message even if interrupted + * + * @param socket The file descriptor for the socket to use + * @param message The message to send + * @param length The length of the message + * @return Zero on success, -1 on error + */ +int full_send(int socket, const char* message, size_t length) +{ + size_t sent; + + while (length > 0) + { + sent = send_message(socket, message, length); + fail_if ((sent < length) && (errno != EINTR)); + message += sent; + length -= sent; + } + return 0; + fail: + return -1; +} + + /** * Check whether a string begins with a specific string, * where neither of the strings are necessarily NUL-terminated diff --git a/src/libmdsserver/util.h b/src/libmdsserver/util.h index 685f971..accf038 100644 --- a/src/libmdsserver/util.h +++ b/src/libmdsserver/util.h @@ -128,6 +128,18 @@ int full_write(int fd, const char* buffer, size_t length); */ char* full_read(int fd, size_t* length); + +/** + * Send a full message even if interrupted + * + * @param socket The file descriptor for the socket to use + * @param message The message to send + * @param length The length of the message + * @return Zero on success, -1 on error + */ +int full_send(int socket, const char* message, size_t length); + + /** * Check whether a string begins with a specific string, * where neither of the strings are necessarily NUL-terminated diff --git a/src/mds-clipboard.c b/src/mds-clipboard.c index 8a52381..cbfed79 100644 --- a/src/mds-clipboard.c +++ b/src/mds-clipboard.c @@ -84,6 +84,17 @@ static clipitem_t* clipboard[CLIPBOARD_LEVELS]; +/** + * Send a full message even if interrupted + * + * @param message:const char* The message to send + * @param length:size_t The length of the message + * @return :int Zero on success, -1 on error + */ +#define full_send(message, length) \ + ((full_send)(socket_fd, message, length)) + + /** * This function will be invoked before `initialise_server` (if not re-exec:ing) * or before `unmarshal_server` (if re-exec:ing) @@ -391,37 +402,6 @@ int master_loop(void) } -/** - * Send a full message even if interrupted - * - * @param message The message to send - * @param length The length of the message - * @return Zero on success, -1 on error - */ -int full_send(const char* message, size_t length) -{ - size_t sent; - - while (length > 0) - { - sent = send_message(socket_fd, message, length); - if (sent > length) - { - eprint("Sent more of a message than exists in the message, aborting."); - return -1; - } - else - fail_if ((sent < length) && (errno != EINTR)); - message += sent; - length -= sent; - } - return 0; - fail: - xperror(*argv); - return -1; -} - - /** * Handle the received message * diff --git a/src/mds-clipboard.h b/src/mds-clipboard.h index 0c23ffb..7d9d6bf 100644 --- a/src/mds-clipboard.h +++ b/src/mds-clipboard.h @@ -89,15 +89,6 @@ typedef struct clipitem -/** - * Send a full message even if interrupted - * - * @param message The message to send - * @param length The length of the message - * @return Zero on success, -1 on error - */ -int full_send(const char* message, size_t length); - /** * Handle the received message * diff --git a/src/mds-colour.c b/src/mds-colour.c index 6b82de1..489137e 100644 --- a/src/mds-colour.c +++ b/src/mds-colour.c @@ -81,6 +81,17 @@ static size_t send_buffer_size = 0; +/** + * Send a full message even if interrupted + * + * @param message:const char* The message to send + * @param length:size_t The length of the message + * @return :int Zero on success, -1 on error + */ +#define full_send(message, length) \ + ((full_send)(socket_fd, message, length)) + + /** * This function will be invoked before `initialise_server` (if not re-exec:ing) * or before `unmarshal_server` (if re-exec:ing) @@ -387,37 +398,6 @@ int handle_set_colour(const char* recv_name, const char* recv_remove, const char } -/** - * Send a full message even if interrupted - * - * @param message The message to send - * @param length The length of the message - * @return Zero on success, -1 on error - */ -int full_send(const char* message, size_t length) -{ - size_t sent; - - while (length > 0) - { - sent = send_message(socket_fd, message, length); - if (sent > length) - { - eprint("Sent more of a message than exists in the message, aborting."); - return -1; - } - else - fail_if ((sent < length) && (errno != EINTR)); - message += sent; - length -= sent; - } - return 0; - fail: - xperror(*argv); - return -1; -} - - /** * This function is called when a signal that * signals that the system to dump state information diff --git a/src/mds-colour.h b/src/mds-colour.h index 72e2ab0..7820c76 100644 --- a/src/mds-colour.h +++ b/src/mds-colour.h @@ -71,15 +71,5 @@ int handle_set_colour(const char* recv_name, const char* recv_remove, const char const char* recv_red, const char* recv_green, const char* recv_blue); -/** - * Send a full message even if interrupted - * - * @param message The message to send - * @param length The length of the message - * @return Zero on success, -1 on error - */ -int full_send(const char* message, size_t length); - - #endif diff --git a/src/mds-echo.c b/src/mds-echo.c index e1366eb..a531812 100644 --- a/src/mds-echo.c +++ b/src/mds-echo.c @@ -79,6 +79,17 @@ static size_t echo_buffer_size = 0; +/** + * Send a full message even if interrupted + * + * @param message:const char* The message to send + * @param length:size_t The length of the message + * @return :int Zero on success, -1 on error + */ +#define full_send(message, length) \ + ((full_send)(socket_fd, message, length)) + + /** * This function will be invoked before `initialise_server` (if not re-exec:ing) * or before `unmarshal_server` (if re-exec:ing) @@ -331,37 +342,6 @@ int echo_message(void) } -/** - * Send a full message even if interrupted - * - * @param message The message to send - * @param length The length of the message - * @return Zero on success, -1 on error - */ -int full_send(const char* message, size_t length) -{ - size_t sent; - - while (length > 0) - { - sent = send_message(socket_fd, message, length); - if (sent > length) - { - eprint("Sent more of a message than exists in the message, aborting."); - return -1; - } - else - fail_if ((sent < length) && (errno != EINTR)); - message += sent; - length -= sent; - } - return 0; - fail: - xperror(*argv); - return -1; -} - - /** * This function is called when a signal that * signals that the system to dump state information diff --git a/src/mds-echo.h b/src/mds-echo.h index fd88e15..ebe5a21 100644 --- a/src/mds-echo.h +++ b/src/mds-echo.h @@ -30,15 +30,6 @@ */ int echo_message(void); -/** - * Send a full message even if interrupted - * - * @param message The message to send - * @param length The length of the message - * @return Zero on success, -1 on error - */ -int full_send(const char* message, size_t length); - #endif diff --git a/src/mds-kkbd.c b/src/mds-kkbd.c index d5ac9e5..9bb8294 100644 --- a/src/mds-kkbd.c +++ b/src/mds-kkbd.c @@ -211,6 +211,17 @@ static int led_compose = LED_COMPOSE; +/** + * Send a full message even if interrupted + * + * @param message:const char* The message to send + * @param length:size_t The length of the message + * @return :int Zero on success, -1 on error + */ +#define full_send(message, length) \ + ((full_send)(socket_fd, message, length)) + + /** * Parse command line arguments * @@ -1391,37 +1402,6 @@ void signal_all(int signo) } -/** - * Send a full message even if interrupted - * - * @param message The message to send - * @param length The length of the message - * @return Zero on success, -1 on error - */ -int full_send(const char* message, size_t length) -{ - size_t sent; - - while (length > 0) - { - sent = send_message(socket_fd, message, length); - if (sent > length) - { - eprint("Sent more of a message than exists in the message, aborting."); - return -1; - } - else - fail_if ((sent < length) && (errno != EINTR)); - message += sent; - length -= sent; - } - return 0; - fail: - xperror(*argv); - return -1; -} - - /** * Acquire access of the keyboard's LED:s * diff --git a/src/mds-kkbd.h b/src/mds-kkbd.h index 3ce2124..8037e83 100644 --- a/src/mds-kkbd.h +++ b/src/mds-kkbd.h @@ -114,15 +114,6 @@ int handle_keycode_map(const char* recv_client_id, const char* recv_message_id, */ int remap_led_cmdline(char* arg); -/** - * Send a full message even if interrupted - * - * @param message The message to send - * @param length The length of the message - * @return Zero on success, -1 on error - */ -int full_send(const char* message, size_t length); - /** * Acquire access of the keyboard's LED:s * diff --git a/src/mds-registry/mds-registry.c b/src/mds-registry/mds-registry.c index a9af91d..df3db51 100644 --- a/src/mds-registry/mds-registry.c +++ b/src/mds-registry/mds-registry.c @@ -21,6 +21,7 @@ #include "globals.h" #include "registry.h" +#include #include #include #include @@ -49,6 +50,17 @@ server_characteristics_t server_characteristics = +/** + * Send a full message even if interrupted + * + * @param message:const char* The message to send + * @param length:size_t The length of the message + * @return :int Zero on success, -1 on error + */ +#define full_send(message, length) \ + ((full_send)(socket_fd, message, length)) + + /** * This function will be invoked before `initialise_server` (if not re-exec:ing) * or before `unmarshal_server` (if re-exec:ing) diff --git a/src/mds-registry/registry.c b/src/mds-registry/registry.c index 660fd6c..359bfc3 100644 --- a/src/mds-registry/registry.c +++ b/src/mds-registry/registry.c @@ -37,6 +37,17 @@ +/** + * Send a full message even if interrupted + * + * @param message:const char* The message to send + * @param length:size_t The length of the message + * @return :int Zero on success, -1 on error + */ +#define full_send(message, length) \ + ((full_send)(socket_fd, message, length)) + + /** * Handle the received message containing a ‘Client closed’-header * diff --git a/src/mds-registry/util.c b/src/mds-registry/util.c index 551904a..1debaa3 100644 --- a/src/mds-registry/util.c +++ b/src/mds-registry/util.c @@ -56,34 +56,3 @@ void reg_table_free_value(size_t obj) free(list); } - -/** - * Send a full message even if interrupted - * - * @param message The message to send - * @param length The length of the message - * @return Zero on success, -1 on error - */ -int full_send(const char* message, size_t length) -{ - size_t sent; - - while (length > 0) - { - sent = send_message(socket_fd, message, length); - if (sent > length) - { - eprint("Sent more of a message than exists in the message, aborting."); - return -1; - } - else - fail_if ((sent < length) && (errno != EINTR)); - message += sent; - length -= sent; - } - return 0; - fail: - xperror(*argv); - return -1; -} - diff --git a/src/mds-registry/util.h b/src/mds-registry/util.h index ea0d492..5699a98 100644 --- a/src/mds-registry/util.h +++ b/src/mds-registry/util.h @@ -36,15 +36,6 @@ void reg_table_free_key(size_t obj); */ void reg_table_free_value(size_t obj); -/** - * Send a full message even if interrupted - * - * @param message The message to send - * @param length The length of the message - * @return Zero on success, -1 on error - */ -int full_send(const char* message, size_t length); - #endif diff --git a/src/mds-vt.c b/src/mds-vt.c index 2490eee..f8a05e7 100644 --- a/src/mds-vt.c +++ b/src/mds-vt.c @@ -721,38 +721,6 @@ void received_switch_vt(int signo) } -/** - * Send a full message even if interrupted - * - * @param socket The file descriptor for the socket to use - * @param message The message to send - * @param length The length of the message - * @return Zero on success, -1 on error - */ -int full_send(int socket, const char* message, size_t length) -{ - size_t sent; - - while (length > 0) - { - sent = send_message(socket, message, length); - if (sent > length) - { - eprint("Sent more of a message than exists in the message, aborting."); - return -1; - } - else - fail_if ((sent < length) && (errno != EINTR)); - message += sent; - length -= sent; - } - return 0; - fail: - xperror(*argv); - return -1; -} - - /** * Get the index of the virtual terminal on which the display should be opened * diff --git a/src/mds-vt.h b/src/mds-vt.h index fe1db5e..2009451 100644 --- a/src/mds-vt.h +++ b/src/mds-vt.h @@ -81,17 +81,6 @@ int handle_configure_vt(const char* client, const char* message, const char* gra void received_switch_vt(int signo); -/** - * Send a full message even if interrupted - * - * @param socket The file descriptor for the socket to use - * @param message The message to send - * @param length The length of the message - * @return Zero on success, -1 on error - */ -int full_send(int socket, const char* message, size_t length); - - /** * Get the index of the virtual terminal on which the display should be opened * -- cgit v1.2.3-70-g09d2