]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib/tsocket: optimize tdgram_recvfrom_done() into tdgram_recvfrom_send()
authorStefan Metzmacher <metze@samba.org>
Fri, 16 May 2025 14:29:19 +0000 (16:29 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 17 Jul 2025 08:59:37 +0000 (08:59 +0000)
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 <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
lib/tsocket/tsocket.c

index 68fdb6c3b407080bd6d61e334ef388f06d9e4c86..3e62aac4f6b2d0373254143292e0d8a2de472f88 100644 (file)
@@ -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;