From 8028c7fa47642b452038176004bea3a8966811ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?= Date: Tue, 11 Oct 2016 10:52:49 +0200 Subject: Bump liberty --- common.c | 70 +--------------------------------------------------------------- 1 file changed, 1 insertion(+), 69 deletions(-) (limited to 'common.c') 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 -- cgit v1.2.3