From 7914c4fc1308b816207a3359b457bdeb0aa3179e Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 19 Feb 2019 19:31:26 +0100 Subject: [PATCH] Drop packet instead of crashing --- src/algo_naive.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/algo_naive.c b/src/algo_naive.c index d704fec..1957230 100644 --- a/src/algo_naive.c +++ b/src/algo_naive.c @@ -166,7 +166,11 @@ void on_tcp_read(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) { // 3. A whole packet has been read, we will find someone to write it sprintf(url, "udp:write:127.0.0.1:%d", bp->ip.ap.str.port); to_fdinfo = evt_core_get_from_url (ctx, url); - if (to_fdinfo == NULL) goto co_error; + if (to_fdinfo == NULL) { + fprintf(stderr, "No fd for URL %s in tcp-read. Dropping packet :( \n", url); + mv_buffer_wtor (app_ctx, fdinfo, bp); + return; + } // 4. We move the buffer and notify the target mv_buffer_rtow (app_ctx, fdinfo, to_fdinfo, bp); @@ -223,7 +227,11 @@ void on_udp_read(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) { // 3. A whole packet has been read, we will find someone to write it sprintf(url, "tcp:write:127.0.0.1:7500"); to_fdinfo = evt_core_get_from_url (ctx, url); - if (to_fdinfo == NULL) goto co_error; + if (to_fdinfo == NULL) { + fprintf(stderr, "No fd for URL %s in udp-read. Dropping packet :( \n", url); + mv_buffer_wtor (app_ctx, fdinfo, bp); + return; + } // 4. We move the buffer and notify the target mv_buffer_rtow (app_ctx, fdinfo, to_fdinfo, bp);