From 2269c74007cbae25875f76195fdc8d548da8f0ce Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Wed, 4 Aug 2010 16:17:14 +0200 Subject: socksify/tsocks support --- libwaitress/src/waitress.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'libwaitress') diff --git a/libwaitress/src/waitress.c b/libwaitress/src/waitress.c index 8746ae0..27f7b3d 100644 --- a/libwaitress/src/waitress.c +++ b/libwaitress/src/waitress.c @@ -34,6 +34,7 @@ THE SOFTWARE. #include #include #include +#include #include "config.h" #include "waitress.h" @@ -225,6 +226,22 @@ WaitressReturn_t WaitressFetchBuf (WaitressHandle_t *waith, char **buf) { return wRet; } +/* poll wrapper that retries after signal interrupts, required for socksify + * wrapper + */ +static int WaitressPollLoop (struct pollfd *fds, nfds_t nfds, int timeout) { + int pollres = -1; + int pollerr = 0; + + do { + pollres = poll (fds, nfds, timeout); + pollerr = errno; + errno = 0; + } while (pollerr == EINTR || pollerr == EINPROGRESS || pollerr == EAGAIN); + + return pollres; +} + /* write () wrapper with poll () timeout * @param socket fd * @param write buffer @@ -238,7 +255,7 @@ static WaitressReturn_t WaitressPollWrite (int sockfd, const char *buf, size_t c int pollres = -1; sockpoll->events = POLLOUT; - pollres = poll (sockpoll, 1, timeout); + pollres = WaitressPollLoop (sockpoll, 1, timeout); if (pollres == 0) { return WAITRESS_RET_TIMEOUT; } else if (pollres == -1) { @@ -264,7 +281,7 @@ static WaitressReturn_t WaitressPollRead (int sockfd, char *buf, size_t count, int pollres = -1; sockpoll->events = POLLIN; - pollres = poll (sockpoll, 1, timeout); + pollres = WaitressPollLoop (sockpoll, 1, timeout); if (pollres == 0) { return WAITRESS_RET_TIMEOUT; } else if (pollres == -1) { @@ -344,7 +361,7 @@ WaitressReturn_t WaitressFetchCall (WaitressHandle_t *waith) { connect (sockfd, res->ai_addr, res->ai_addrlen); sockpoll.events = POLLOUT; - pollres = poll (&sockpoll, 1, waith->socktimeout); + pollres = WaitressPollLoop (&sockpoll, 1, waith->socktimeout); freeaddrinfo (res); if (pollres == 0) { return WAITRESS_RET_TIMEOUT; -- cgit v1.2.3