aboutsummaryrefslogtreecommitdiffstats
path: root/src/libmdsserver
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-08-19 13:37:19 +0200
committerMattias Andrée <maandree@operamail.com>2015-08-19 13:37:19 +0200
commitce5160a39d26a8e7cf0633d0d144436a5156837a (patch)
tree5ac139854c4d620f7549c4be4c1231644ba0a49b /src/libmdsserver
parenttypo + continued work on mds-colour (diff)
downloadmds-ce5160a39d26a8e7cf0633d0d144436a5156837a.tar.gz
mds-ce5160a39d26a8e7cf0633d0d144436a5156837a.tar.bz2
mds-ce5160a39d26a8e7cf0633d0d144436a5156837a.tar.xz
put full_send in libmdsserver, clients that only has one socket uses a macro to remove the socket parameter
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/libmdsserver/util.c25
-rw-r--r--src/libmdsserver/util.h12
2 files changed, 37 insertions, 0 deletions
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