aboutsummaryrefslogtreecommitdiff
path: root/src/common/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/util.c')
-rw-r--r--src/common/util.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 3a80b94da..21584093c 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -88,6 +88,21 @@ void tv_addms(struct timeval *a, long ms) {
a->tv_usec %= 1000000;
}
+/* a wrapper for write(2) that makes sure to write all count bytes.
+ * Only use if fd is a blocking socket. */
+int write_all(int fd, const void *buf, size_t count) {
+ int written = 0;
+ int result;
+
+ while(written != count) {
+ result = write(fd, buf+written, count-written);
+ if(result<0)
+ return -1;
+ written += result;
+ }
+ return count;
+}
+
void set_socket_nonblocking(int socket)
{
#ifdef MS_WINDOWS