diff options
Diffstat (limited to '')
-rw-r--r-- | doc/info/mds.texinfo | 8 | ||||
-rw-r--r-- | src/libmdsserver/util.c | 25 | ||||
-rw-r--r-- | src/libmdsserver/util.h | 12 | ||||
-rw-r--r-- | src/mds-clipboard.c | 42 | ||||
-rw-r--r-- | src/mds-clipboard.h | 9 | ||||
-rw-r--r-- | src/mds-colour.c | 42 | ||||
-rw-r--r-- | src/mds-colour.h | 10 | ||||
-rw-r--r-- | src/mds-echo.c | 42 | ||||
-rw-r--r-- | src/mds-echo.h | 9 | ||||
-rw-r--r-- | src/mds-kkbd.c | 42 | ||||
-rw-r--r-- | src/mds-kkbd.h | 9 | ||||
-rw-r--r-- | src/mds-registry/mds-registry.c | 12 | ||||
-rw-r--r-- | src/mds-registry/registry.c | 11 | ||||
-rw-r--r-- | src/mds-registry/util.c | 31 | ||||
-rw-r--r-- | src/mds-registry/util.h | 9 | ||||
-rw-r--r-- | src/mds-vt.c | 32 | ||||
-rw-r--r-- | 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 @@ -314,6 +314,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 @@ -85,6 +85,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) * @@ -392,37 +403,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 * * @return Zero on success, -1 on error 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 @@ -90,15 +90,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 * * @return Zero on success, -1 on error 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 @@ -82,6 +82,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) * @@ -388,37 +399,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 * and statistics has been received 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 @@ -80,6 +80,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) * @@ -332,37 +343,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 * and statistics has been received 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 @@ -212,6 +212,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 * * @return Non-zero on error @@ -1392,37 +1403,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 * * @return Zero on success, -1 on error 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 @@ -115,15 +115,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 * * @return Zero on success, -1 on error 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 <libmdsserver/util.h> #include <libmdsserver/macros.h> #include <libmdsserver/hash-help.h> #include <libmdsserver/linked-list.h> @@ -50,6 +51,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 @@ -38,6 +38,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 * * @return Zero on success -1 on error or interruption, 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 @@ -722,38 +722,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 * * @return The index of the virtual terminal on which the display should be opened, -1 on error 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 @@ -82,17 +82,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); - - -/** * Get the index of the virtual terminal on which the display should be opened * * @return The index of the virtual terminal on which the display should be opened, -1 on error |