From: Stefan Metzmacher Date: Fri, 16 May 2025 14:29:19 +0000 (+0200) Subject: lib/tsocket: optimize tdgram_recvfrom_done() into tdgram_recvfrom_send() X-Git-Tag: tdb-1.4.14~109 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=a8c208053306aa26c0faf1713bfcbc49d2825eda;p=thirdparty%2Fsamba.git lib/tsocket: optimize tdgram_recvfrom_done() into tdgram_recvfrom_send() For callers using tdgram_bsd_optimize_recvfrom() it is every useful to know it data was already waiting in the socket. In that case the result from tdgram_bsd_recvfrom_send() would already report tevent_req_is_in_progress() as false. But the result of tdgram_recvfrom_send() available to the caller would see tevent_req_is_in_progress() reporting true. With this change also the result of tdgram_recvfrom_send() would report tevent_req_is_in_progress() as false, which will be useful for callers, which would otherwise set a timeout on the request. Signed-off-by: Stefan Metzmacher Reviewed-by: Ralph Boehme --- diff --git a/lib/tsocket/tsocket.c b/lib/tsocket/tsocket.c index 68fdb6c3b40..3e62aac4f6b 100644 --- a/lib/tsocket/tsocket.c +++ b/lib/tsocket/tsocket.c @@ -214,6 +214,22 @@ struct tevent_req *tdgram_recvfrom_send(TALLOC_CTX *mem_ctx, goto post; } tevent_req_set_callback(subreq, tdgram_recvfrom_done, req); + if (!tevent_req_is_in_progress(subreq)) { + /* + * Allow the caller of + * tdgram_recvfrom_send() to + * see tevent_req_is_in_progress() + * reporting false too. + * + * Useful for callers using + * tdgram_bsd_optimize_recvfrom(true) + * in order to check if data + * was already waiting in the + * receice buffer. + */ + tdgram_recvfrom_done(subreq); + goto post; + } return req;