fnet.c

Simple C networking library
git clone git://git.finwo.net/lib/fnet.c
Log | Files | Refs | README

commit 46d565babed23e51bc83ed69bbc109d1b51a05fb
parent 5a22e46e07a2a203357f7103574083aa1cfb5b30
Author: Yersa Nordman <yersa@finwo.nl>
Date:   Mon,  1 Jan 2024 15:23:06 +0100

Prevent double call of onClose if shutdown is called during the callback

Diffstat:
Msrc/fnet.c | 8+++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/fnet.c b/src/fnet.c @@ -584,6 +584,7 @@ FNET_RETURNCODE fnet_write(const struct fnet_t *connection, struct buf *buf) { FNET_RETURNCODE fnet_close(const struct fnet_t *connection) { /* printf("Internal fnet_close\n"); */ struct fnet_internal_t *conn = (struct fnet_internal_t *)connection; + FNET_CALLBACK(cb) = NULL; int i; // Checking arguments are given @@ -611,14 +612,15 @@ FNET_RETURNCODE fnet_close(const struct fnet_t *connection) { conn->ext.status = FNET_STATUS_CLOSED; if (conn->ext.onClose) { - conn->ext.onClose(&((struct fnet_ev){ + cb = conn->ext.onClose; + conn->ext.onClose = NULL; + + cb(&((struct fnet_ev){ .connection = (struct fnet_t *)conn, .type = FNET_EVENT_CLOSE, .buffer = NULL, .udata = conn->ext.udata, })); - - conn->ext.onClose = NULL; } return FNET_RETURNCODE_OK;