mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
Check for EINTR correctly on windows
(even though these are nonblocking calls and EINTR shouldn't be possible). Also, log what error we're seing if drain_fn fails.
This commit is contained in:
parent
9d1801b4b9
commit
720a9ccb2f
3
changes/bug16741
Normal file
3
changes/bug16741
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
o Minor bugfixes:
|
||||||
|
- Check correctly for windows socket errors in the workqueue backend.
|
||||||
|
Fixes bug 16741; bugfix on 0.2.6.3-alpha.
|
@ -576,6 +576,8 @@ int network_init(void);
|
|||||||
((e) == WSAEMFILE || (e) == WSAENOBUFS)
|
((e) == WSAEMFILE || (e) == WSAENOBUFS)
|
||||||
/** Return true if e is EADDRINUSE or the local equivalent. */
|
/** Return true if e is EADDRINUSE or the local equivalent. */
|
||||||
#define ERRNO_IS_EADDRINUSE(e) ((e) == WSAEADDRINUSE)
|
#define ERRNO_IS_EADDRINUSE(e) ((e) == WSAEADDRINUSE)
|
||||||
|
/** Return true if e is EINTR or the local equivalent */
|
||||||
|
#define ERRNO_IS_EINTR(e) ((e) == WSAEINTR || 0)
|
||||||
int tor_socket_errno(tor_socket_t sock);
|
int tor_socket_errno(tor_socket_t sock);
|
||||||
const char *tor_socket_strerror(int e);
|
const char *tor_socket_strerror(int e);
|
||||||
#else
|
#else
|
||||||
@ -586,6 +588,7 @@ const char *tor_socket_strerror(int e);
|
|||||||
#else
|
#else
|
||||||
#define ERRNO_IS_EAGAIN(e) ((e) == EAGAIN || (e) == EWOULDBLOCK)
|
#define ERRNO_IS_EAGAIN(e) ((e) == EAGAIN || (e) == EWOULDBLOCK)
|
||||||
#endif
|
#endif
|
||||||
|
#define ERRNO_IS_EINTR(e) ((e) == EINTR || 0)
|
||||||
#define ERRNO_IS_EINPROGRESS(e) ((e) == EINPROGRESS || 0)
|
#define ERRNO_IS_EINPROGRESS(e) ((e) == EINPROGRESS || 0)
|
||||||
#define ERRNO_IS_CONN_EINPROGRESS(e) ((e) == EINPROGRESS || 0)
|
#define ERRNO_IS_CONN_EINPROGRESS(e) ((e) == EINPROGRESS || 0)
|
||||||
#define ERRNO_IS_ACCEPT_EAGAIN(e) \
|
#define ERRNO_IS_ACCEPT_EAGAIN(e) \
|
||||||
|
@ -88,7 +88,7 @@ in_main_thread(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(HAVE_EVENTFD) || defined(HAVE_PIPE)
|
#if defined(HAVE_EVENTFD) || defined(HAVE_PIPE)
|
||||||
/* non-interruptable versions */
|
/* As write(), but retry on EINTR */
|
||||||
static int
|
static int
|
||||||
write_ni(int fd, const void *buf, size_t n)
|
write_ni(int fd, const void *buf, size_t n)
|
||||||
{
|
{
|
||||||
@ -99,6 +99,7 @@ write_ni(int fd, const void *buf, size_t n)
|
|||||||
goto again;
|
goto again;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
/* As read(), but retry on EINTR */
|
||||||
static int
|
static int
|
||||||
read_ni(int fd, void *buf, size_t n)
|
read_ni(int fd, void *buf, size_t n)
|
||||||
{
|
{
|
||||||
@ -111,30 +112,32 @@ read_ni(int fd, void *buf, size_t n)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* non-interruptable versions */
|
/** As send(), but retry on EINTR. */
|
||||||
static int
|
static int
|
||||||
send_ni(int fd, const void *buf, size_t n, int flags)
|
send_ni(int fd, const void *buf, size_t n, int flags)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
again:
|
again:
|
||||||
r = (int) send(fd, buf, n, flags);
|
r = (int) send(fd, buf, n, flags);
|
||||||
if (r < 0 && errno == EINTR)
|
if (r < 0 && ERRNO_IS_EINTR(tor_socket_errno(fd)))
|
||||||
goto again;
|
goto again;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** As recv(), but retry on EINTR. */
|
||||||
static int
|
static int
|
||||||
recv_ni(int fd, void *buf, size_t n, int flags)
|
recv_ni(int fd, void *buf, size_t n, int flags)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
again:
|
again:
|
||||||
r = (int) recv(fd, buf, n, flags);
|
r = (int) recv(fd, buf, n, flags);
|
||||||
if (r < 0 && errno == EINTR)
|
if (r < 0 && ERRNO_IS_EINTR(tor_socket_errno(fd)))
|
||||||
goto again;
|
goto again;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_EVENTFD
|
#ifdef HAVE_EVENTFD
|
||||||
|
/* Increment the event count on an eventfd <b>fd</b> */
|
||||||
static int
|
static int
|
||||||
eventfd_alert(int fd)
|
eventfd_alert(int fd)
|
||||||
{
|
{
|
||||||
@ -145,6 +148,7 @@ eventfd_alert(int fd)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Drain all events from an eventfd <b>fd</b>. */
|
||||||
static int
|
static int
|
||||||
eventfd_drain(int fd)
|
eventfd_drain(int fd)
|
||||||
{
|
{
|
||||||
@ -157,6 +161,7 @@ eventfd_drain(int fd)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_PIPE
|
#ifdef HAVE_PIPE
|
||||||
|
/** Send a byte over a pipe. Return 0 on success or EAGAIN; -1 on error */
|
||||||
static int
|
static int
|
||||||
pipe_alert(int fd)
|
pipe_alert(int fd)
|
||||||
{
|
{
|
||||||
@ -166,6 +171,8 @@ pipe_alert(int fd)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Drain all input from a pipe <b>fd</b> and ignore it. Return 0 on
|
||||||
|
* success, -1 on error. */
|
||||||
static int
|
static int
|
||||||
pipe_drain(int fd)
|
pipe_drain(int fd)
|
||||||
{
|
{
|
||||||
@ -181,6 +188,8 @@ pipe_drain(int fd)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/** Send a byte on socket <b>fd</b>t. Return 0 on success or EAGAIN,
|
||||||
|
* -1 on error. */
|
||||||
static int
|
static int
|
||||||
sock_alert(tor_socket_t fd)
|
sock_alert(tor_socket_t fd)
|
||||||
{
|
{
|
||||||
@ -190,6 +199,8 @@ sock_alert(tor_socket_t fd)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Drain all the input from a socket <b>fd</b>, and ignore it. Return 0 on
|
||||||
|
* success, -1 on error. */
|
||||||
static int
|
static int
|
||||||
sock_drain(tor_socket_t fd)
|
sock_drain(tor_socket_t fd)
|
||||||
{
|
{
|
||||||
|
@ -473,7 +473,8 @@ replyqueue_process(replyqueue_t *queue)
|
|||||||
if (queue->alert.drain_fn(queue->alert.read_fd) < 0) {
|
if (queue->alert.drain_fn(queue->alert.read_fd) < 0) {
|
||||||
static ratelim_t warn_limit = RATELIM_INIT(7200);
|
static ratelim_t warn_limit = RATELIM_INIT(7200);
|
||||||
log_fn_ratelim(&warn_limit, LOG_WARN, LD_GENERAL,
|
log_fn_ratelim(&warn_limit, LOG_WARN, LD_GENERAL,
|
||||||
"Failure from drain_fd");
|
"Failure from drain_fd: %s",
|
||||||
|
tor_socket_strerror(tor_socket_errno(queue->alert.read_fd)));
|
||||||
}
|
}
|
||||||
|
|
||||||
tor_mutex_acquire(&queue->lock);
|
tor_mutex_acquire(&queue->lock);
|
||||||
|
Loading…
Reference in New Issue
Block a user