aboutsummaryrefslogtreecommitdiff
path: root/src/pevent.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pevent.c')
-rw-r--r--src/pevent.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/pevent.c b/src/pevent.c
index 3007472..60a954d 100644
--- a/src/pevent.c
+++ b/src/pevent.c
@@ -85,20 +85,23 @@ int event_loop(event_ctx *ctx, on_event_cb on_event, void *user_data)
n = epoll_pwait(ctx->epoll_fd, ctx->events, POTD_MAXEVENTS, -1, &eset);
if (errno == EINTR)
continue;
- if (n < 0)
+ if (n < 0) {
+ ctx->active = 0;
break;
+ }
for (i = 0; i < n; ++i) {
+ ctx->current_event = i;
+
if ((ctx->events[i].events & EPOLLERR) ||
(ctx->events[i].events & EPOLLHUP) ||
+ (ctx->events[i].events & EPOLLRDHUP) ||
(!(ctx->events[i].events & EPOLLIN)))
{
E_STRERR("Event epoll for descriptor %d",
ctx->events[i].data.fd);
ctx->active = 0;
- break;
} else {
- ctx->current_event = i;
if (!on_event(ctx, ctx->events[i].data.fd, user_data))
W2("Event callback failed: [fd: %d , npoll: %d]",
ctx->events[i].data.fd, n);
@@ -139,7 +142,6 @@ event_forward_connection(event_ctx *ctx, int dest_fd, on_data_cb on_data,
siz = read(ev->data.fd, &buf[0], BUFSIZ);
saved_errno = errno;
} else break;
-
if (saved_errno == EAGAIN)
break;
@@ -168,6 +170,7 @@ event_forward_connection(event_ctx *ctx, int dest_fd, on_data_cb on_data,
}
if (has_input) {
+ errno = 0;
siz = write(dest_fd, &buf[0], siz);
switch (siz) {
@@ -189,5 +192,11 @@ event_forward_connection(event_ctx *ctx, int dest_fd, on_data_cb on_data,
}
D2("Connection state: %d", rc);
+ if (rc != CON_OK) {
+ if (shutdown(ev->data.fd, SHUT_RDWR))
+ E_STRERR("Shutdown source socket fd %d", ev->data.fd);
+ if (shutdown(dest_fd, SHUT_RDWR))
+ E_STRERR("Shutdown dest socket fd %d", dest_fd);
+ }
return rc;
}