[PATCH 3/9] server: Defer postprocessing until after setting initial status in recv_socket handler.

Jinoh Kang jinoh.kang.kr at gmail.com
Mon Feb 21 04:49:11 CST 2022


This allows the client to postpone the initial I/O until after the
server has actually queued the I/O request.  The server should perform
the postprocessing only after the initial I/O has been done.

In the case of recv_socket, the manipulation of event flags shall
ideally be done *after* (not *before*) the client has attempted the
initial I/O, since the readiness of the socket may change due to I/O.

Signed-off-by: Jinoh Kang <jinoh.kang.kr at gmail.com>
---
 server/sock.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/server/sock.c b/server/sock.c
index 91f98556552..e2717b2c867 100644
--- a/server/sock.c
+++ b/server/sock.c
@@ -3393,6 +3393,24 @@ struct object *create_socket_device( struct object *root, const struct unicode_s
     return create_named_object( root, &socket_device_ops, name, attr, sd );
 }
 
+static void recv_socket_initial_callback( void *private, unsigned int status )
+{
+    struct sock *sock = (struct sock *)private;
+    sock->pending_events &= ~AFD_POLL_READ;
+    sock->reported_events &= ~AFD_POLL_READ;
+    sock_reselect( sock );
+    release_object( sock );
+}
+
+static void recv_socket_initial_callback_oob( void *private, unsigned int status )
+{
+    struct sock *sock = (struct sock *)private;
+    sock->pending_events &= ~AFD_POLL_OOB;
+    sock->reported_events &= ~AFD_POLL_OOB;
+    sock_reselect( sock );
+    release_object( sock );
+}
+
 DECL_HANDLER(recv_socket)
 {
     struct sock *sock = (struct sock *)get_handle_obj( current->process, req->async.handle, 0, &sock_ops );
@@ -3430,22 +3448,21 @@ DECL_HANDLER(recv_socket)
     if (status == STATUS_PENDING && !req->force_async && sock->nonblocking)
         status = STATUS_DEVICE_NOT_READY;
 
-    sock->pending_events &= ~(req->oob ? AFD_POLL_OOB : AFD_POLL_READ);
-    sock->reported_events &= ~(req->oob ? AFD_POLL_OOB : AFD_POLL_READ);
-
     if ((async = create_request_async( fd, get_fd_comp_flags( fd ), &req->async )))
     {
         set_error( status );
 
+        async_set_initial_status_callback( async,
+                                           req->oob ? recv_socket_initial_callback_oob
+                                                    : recv_socket_initial_callback,
+                                           grab_object( sock ));
+
         if (timeout)
             async_set_timeout( async, timeout, STATUS_IO_TIMEOUT );
 
         if (status == STATUS_PENDING || status == STATUS_ALERTED)
             queue_async( &sock->read_q, async );
 
-        /* always reselect; we changed reported_events above */
-        sock_reselect( sock );
-
         reply->wait = async_handoff( async, NULL, 0 );
         reply->options = get_fd_options( fd );
         reply->nonblocking = sock->nonblocking;
-- 
2.34.1




More information about the wine-devel mailing list