Project "Tuxbox-GIT: apps": The branch, master has been updated via 9238e6a29abd4d55c50e21fefab0dc6a779625c1 (commit) from a1e4044f02243c233e6302c39420da0015672b87 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 9238e6a29abd4d55c50e21fefab0dc6a779625c1 Author: GetAway <get-a...@t-online.de> Date: Thu Jul 2 22:27:39 2015 +0200 basicsocket: fix poll Signed-off-by: GetAway <get-a...@t-online.de> diff --git a/misc/libs/libconnection/basicserver.cpp b/misc/libs/libconnection/basicserver.cpp index 7d5a0c7..f892d24 100644 --- a/misc/libs/libconnection/basicserver.cpp +++ b/misc/libs/libconnection/basicserver.cpp @@ -36,8 +36,8 @@ #include <sys/un.h> #include <unistd.h> -#define RECEIVE_TIMEOUT_IN_SECONDS 5 -#define SEND_TIMEOUT_IN_SECONDS 5 +#define RECEIVE_TIMEOUT_IN_SECONDS 60 +#define SEND_TIMEOUT_IN_SECONDS 60 bool CBasicServer::receive_data(int fd, void * data, const size_t size) { diff --git a/misc/libs/libconnection/basicsocket.cpp b/misc/libs/libconnection/basicsocket.cpp index cf69656..b6b282d 100644 --- a/misc/libs/libconnection/basicsocket.cpp +++ b/misc/libs/libconnection/basicsocket.cpp @@ -29,22 +29,24 @@ #include <stdio.h> #include <sys/socket.h> #include <sys/types.h> +#include <unistd.h> #include <poll.h> bool send_data(int fd, const void * data, const size_t size, const timeval timeout) { - char *buffer = (char *)data; size_t left = size; while (left > 0) { + const void * buffer = (void *)((char *)data + (size - left)); int len = ::send(fd, buffer, left, MSG_DONTWAIT | MSG_NOSIGNAL); - if (len < 0) + if (len == -1) { - perror("[basicsocket] send_data"); - - if (errno != EINTR && errno != EAGAIN) + int olderr = errno; + if (errno != EAGAIN) // this is "write would block...", which is not an error + fprintf(stderr,"[basicsocket] send_data: %m (n = %d/%d, pid = %d)\n", left, size, getpid()); + if (olderr == EPIPE || olderr == ESPIPE) return false; struct pollfd pfd; @@ -59,7 +61,7 @@ bool send_data(int fd, const void * data, const size_t size, const timeval timeo printf("[basicsocket] send timed out.\n"); return false; } - if (rc < 0) + if (rc == -1) { perror("[basicsocket] send_data poll"); return false; @@ -71,10 +73,7 @@ bool send_data(int fd, const void * data, const size_t size, const timeval timeo } } else - { - buffer += len; left -= len; - } } return true; } @@ -82,7 +81,6 @@ bool send_data(int fd, const void * data, const size_t size, const timeval timeo bool receive_data(int fd, void * data, const size_t size, const timeval timeout) { - char *buffer = (char *)data; size_t left = size; while (left > 0) @@ -92,45 +90,48 @@ bool receive_data(int fd, void * data, const size_t size, const timeval timeout) pfd.events = POLLIN; pfd.revents = 0; - int to = timeout.tv_sec * 1000 + timeout.tv_usec / 1000; - - int rc = poll(&pfd, 1, to); + int rc = poll(&pfd, 1, timeout.tv_sec * 1000 + timeout.tv_usec / 1000); if (rc == 0) { - printf("[basicsocket] recv timed out.\n"); + printf("[basicsocket] receive timed out. waiting process %d\n", getpid()); return false; } - if (rc < 0) + if (rc == -1) { perror("[basicsocket] recv_data poll"); return false; } if (!(pfd.revents & POLLIN)) { - perror("[basicsocket] recv_data POLLIN"); + perror("[basicsocket] receive_data POLLIN"); return false; } - int len = ::recv(fd, data, left, MSG_DONTWAIT | MSG_NOSIGNAL); + void * buffer = (void *)((char *)data + (size - left)); + int len = ::recv(fd, buffer, left, MSG_DONTWAIT | MSG_NOSIGNAL); - if (len > 0) { - left -= len; - buffer += len; - } else if (len < 0) + if ((len == 0) || (len == -1)) { - perror("[basicsocket] receive_data"); - if (errno != EINTR && errno != EAGAIN) + if (len == -1) + { + perror("[basicsocket] receive_data"); + + if (errno == EPIPE || errno == ESPIPE) + return false; + } + else + { + /* + * silently return false + * + * printf("[basicsocket] no more data\n"); + */ return false; + } + } - else // len == 0 - { - /* - * silently return false - * - * printf("[basicsocket] no more data\n"); - */ - return false; - } + else + left -= len; } return true; } ----------------------------------------------------------------------- Summary of changes: misc/libs/libconnection/basicserver.cpp | 4 +- misc/libs/libconnection/basicsocket.cpp | 65 ++++++++++++++++--------------- 2 files changed, 35 insertions(+), 34 deletions(-) -- Tuxbox-GIT: apps ------------------------------------------------------------------------------ Don't Limit Your Business. Reach for the Cloud. GigeNET's Cloud Solutions provide you with the tools and support that you need to offload your IT needs and focus on growing your business. Configured For All Businesses. Start Your Cloud Today. https://www.gigenetcloud.com/ _______________________________________________ Tuxbox-cvs-commits mailing list Tuxbox-cvs-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tuxbox-cvs-commits