From 88a14985dbd7093df73c46e00a74539382e79e16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Thu, 8 Feb 2024 12:31:09 +0100 Subject: [PATCH] Add isc_nm_read_stop() and remove .reading member from ccmsg We need to stop reading when calling isc_ccmsg_disconnect() as the reading handle doesn't have to be last because sending might be in progress. After that, we can safely remove .reading member because the reading would not be called after the disconnect has been called. The ccmsg_senddone() should also not call the recv callback if the sending failed, that's the job of the caller's send callback - in fact it already does that, so the code in ccmsg_senddone() was superfluous. --- lib/isccc/ccmsg.c | 11 ++--------- lib/isccc/include/isccc/ccmsg.h | 1 - 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/isccc/ccmsg.c b/lib/isccc/ccmsg.c index 80d622da79..4c033dd975 100644 --- a/lib/isccc/ccmsg.c +++ b/lib/isccc/ccmsg.c @@ -102,10 +102,7 @@ recv_data(isc_nmhandle_t *handle, isc_result_t eresult, isc_region_t *region, done: isc_nm_read_stop(handle); - if (ccmsg->reading) { - ccmsg->reading = false; - ccmsg->recv_cb(handle, eresult, ccmsg->recv_cbarg); - } + ccmsg->recv_cb(handle, eresult, ccmsg->recv_cbarg); return; } @@ -145,7 +142,6 @@ isccc_ccmsg_readmessage(isccc_ccmsg_t *ccmsg, isc_nm_cb_t cb, void *cbarg) { ccmsg->recv_cbarg = cbarg; ccmsg->length_received = false; - ccmsg->reading = true; isc_nm_read(ccmsg->handle, recv_data, ccmsg); } @@ -159,10 +155,6 @@ ccmsg_senddone(isc_nmhandle_t *handle, isc_result_t eresult, void *arg) { ccmsg->send_cb(handle, eresult, ccmsg->send_cbarg); ccmsg->send_cb = NULL; - if (eresult != ISC_R_SUCCESS && ccmsg->reading) { - recv_data(handle, eresult, NULL, ccmsg); - } - isc_nmhandle_detach(&handle); } @@ -184,6 +176,7 @@ isccc_ccmsg_disconnect(isccc_ccmsg_t *ccmsg) { REQUIRE(VALID_CCMSG(ccmsg)); if (ccmsg->handle != NULL) { + isc_nm_read_stop(ccmsg->handle); isc_nmhandle_close(ccmsg->handle); isc_nmhandle_detach(&ccmsg->handle); } diff --git a/lib/isccc/include/isccc/ccmsg.h b/lib/isccc/include/isccc/ccmsg.h index 7a20a7c2e1..5120732901 100644 --- a/lib/isccc/include/isccc/ccmsg.h +++ b/lib/isccc/include/isccc/ccmsg.h @@ -54,7 +54,6 @@ typedef struct isccc_ccmsg { void *recv_cbarg; isc_nm_cb_t send_cb; void *send_cbarg; - bool reading; } isccc_ccmsg_t; ISC_LANG_BEGINDECLS