aboutsummaryrefslogtreecommitdiff
path: root/common.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-10-11 10:52:49 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2016-10-11 10:52:49 +0200
commit8028c7fa47642b452038176004bea3a8966811ac (patch)
tree5c51ea2fd404b0ff4c362b402373458d5011e4cc /common.c
parent43de836b919db7f5c10f63a4a788acbc2752e74f (diff)
downloadxK-8028c7fa47642b452038176004bea3a8966811ac.tar.gz
xK-8028c7fa47642b452038176004bea3a8966811ac.tar.xz
xK-8028c7fa47642b452038176004bea3a8966811ac.zip
Bump liberty
Diffstat (limited to 'common.c')
-rw-r--r--common.c70
1 files changed, 1 insertions, 69 deletions
diff --git a/common.c b/common.c
index 282916c..4bbebd9 100644
--- a/common.c
+++ b/common.c
@@ -108,79 +108,11 @@ xwrite (int fd, const char *data, size_t len, struct error **e)
if (res >= 0)
written += res;
else if (errno != EINTR)
- FAIL ("%s", strerror (errno));
+ return error_set (e, "%s", strerror (errno));
}
return true;
}
-// --- Simple network I/O ------------------------------------------------------
-
-// TODO: move to liberty and remove from dwmstatus.c as well
-
-#define SOCKET_IO_OVERFLOW (8 << 20) ///< How large a read buffer can be
-
-enum socket_io_result
-{
- SOCKET_IO_OK, ///< Completed successfully
- SOCKET_IO_EOF, ///< Connection shut down by peer
- SOCKET_IO_ERROR ///< Connection error
-};
-
-static enum socket_io_result
-socket_io_try_read (int socket_fd, struct str *rb, struct error **e)
-{
- // We allow buffering of a fair amount of data, however within reason,
- // so that it's not so easy to flood us and cause an allocation failure
- ssize_t n_read;
- while (rb->len < SOCKET_IO_OVERFLOW)
- {
- str_ensure_space (rb, 4096);
- n_read = recv (socket_fd, rb->str + rb->len,
- rb->alloc - rb->len - 1 /* null byte */, 0);
-
- if (n_read > 0)
- {
- rb->str[rb->len += n_read] = '\0';
- continue;
- }
- if (n_read == 0)
- return SOCKET_IO_EOF;
-
- if (errno == EAGAIN)
- return SOCKET_IO_OK;
- if (errno == EINTR)
- continue;
-
- error_set (e, "%s", strerror (errno));
- return SOCKET_IO_ERROR;
- }
- return SOCKET_IO_OK;
-}
-
-static enum socket_io_result
-socket_io_try_write (int socket_fd, struct str *wb, struct error **e)
-{
- ssize_t n_written;
- while (wb->len)
- {
- n_written = send (socket_fd, wb->str, wb->len, 0);
- if (n_written >= 0)
- {
- str_remove_slice (wb, 0, n_written);
- continue;
- }
-
- if (errno == EAGAIN)
- return SOCKET_IO_OK;
- if (errno == EINTR)
- continue;
-
- error_set (e, "%s", strerror (errno));
- return SOCKET_IO_ERROR;
- }
- return SOCKET_IO_OK;
-}
-
// --- Logging -----------------------------------------------------------------
static void