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.
This commit is contained in:
Ondřej Surý 2024-02-08 12:31:09 +01:00
parent 5964eb4796
commit 88a14985db
No known key found for this signature in database
GPG key ID: 2820F37E873DEA41
2 changed files with 2 additions and 10 deletions

View file

@ -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);
}

View file

@ -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