diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2018-05-18 23:38:46 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2018-05-18 23:38:46 +0200 |
commit | f48123bfaa46f5c93fe4b56423c6b52153e5c9b1 (patch) | |
tree | 4e3683e92251d4f3d8fc8cc3fde473a017e20436 /src/pevent.c | |
parent | ac5acb542df4b9e449dc2413388890ca1e30984e (diff) |
POTD skeleton #61.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'src/pevent.c')
-rw-r--r-- | src/pevent.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/pevent.c b/src/pevent.c index 70fb311..3007472 100644 --- a/src/pevent.c +++ b/src/pevent.c @@ -113,14 +113,15 @@ int event_loop(event_ctx *ctx, on_event_cb on_event, void *user_data) } forward_state -event_forward_connection(event_ctx *ctx, int dest_fd) +event_forward_connection(event_ctx *ctx, int dest_fd, on_data_cb on_data, + void *user_data) { int data_avail = 1; int has_input; int saved_errno; forward_state rc = CON_OK; ssize_t siz; - char buf[BUFSIZ+sizeof(long)]; + char buf[BUFSIZ]; struct epoll_event *ev; assert(ctx->current_event >= 0 && @@ -151,7 +152,6 @@ event_forward_connection(event_ctx *ctx, int dest_fd) rc = CON_IN_TERMINATED; break; default: - buf[siz] = 0; D2("Read %lu bytes from fd %d", siz, ev->data.fd); break; } @@ -159,6 +159,14 @@ event_forward_connection(event_ctx *ctx, int dest_fd) if (rc != CON_OK) break; + if (on_data && + on_data(ctx, ev->data.fd, dest_fd, buf, siz, user_data)) + { + W2("On data callback failed, not forwarding from %d to %d", + ev->data.fd, dest_fd); + continue; + } + if (has_input) { siz = write(dest_fd, &buf[0], siz); |