From 03d187b1475f5ab82c47421452c27a9cab81b472 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Sun, 31 Oct 2021 12:40:56 +0000 Subject: [PATCH] Fix #1375 - change event processing order --- mongoose.c | 5 ++++- src/event.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/mongoose.c b/mongoose.c index fee4a69a..0496964d 100644 --- a/mongoose.c +++ b/mongoose.c @@ -385,8 +385,11 @@ void mg_resolve(struct mg_connection *c, struct mg_str *name, int ms) { void mg_call(struct mg_connection *c, int ev, void *ev_data) { - if (c->pfn != NULL) c->pfn(c, ev, ev_data, c->pfn_data); + // Run user-defined handler first, in order to give it an ability + // to intercept processing (e.g. clean input buffer) before the + // protocol handler kicks in if (c->fn != NULL) c->fn(c, ev, ev_data, c->fn_data); + if (c->pfn != NULL) c->pfn(c, ev, ev_data, c->pfn_data); } void mg_error(struct mg_connection *c, const char *fmt, ...) { diff --git a/src/event.c b/src/event.c index 501c26c3..f7d0036f 100644 --- a/src/event.c +++ b/src/event.c @@ -4,8 +4,11 @@ #include "util.h" void mg_call(struct mg_connection *c, int ev, void *ev_data) { - if (c->pfn != NULL) c->pfn(c, ev, ev_data, c->pfn_data); + // Run user-defined handler first, in order to give it an ability + // to intercept processing (e.g. clean input buffer) before the + // protocol handler kicks in if (c->fn != NULL) c->fn(c, ev, ev_data, c->fn_data); + if (c->pfn != NULL) c->pfn(c, ev, ev_data, c->pfn_data); } void mg_error(struct mg_connection *c, const char *fmt, ...) {