From e50d49c17a3c9d51621a5781dda1a107bee0b949 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Wed, 22 Feb 2017 14:51:17 +0100 Subject: [PATCH] server: Moved server-independent parts of pipe_server_flush into separated function. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- server/named_pipe.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/server/named_pipe.c b/server/named_pipe.c index 4a4769b58b9..6861e0fd3c9 100644 --- a/server/named_pipe.c +++ b/server/named_pipe.c @@ -548,23 +548,31 @@ static void check_flushed( void *arg ) } } +static obj_handle_t pipe_end_flush( struct pipe_end *pipe_end, struct async *async, int blocking ) +{ + obj_handle_t handle = 0; + + if (!fd_queue_async( pipe_end->fd, async, ASYNC_TYPE_WAIT )) return 0; + + if (!blocking || (handle = alloc_handle( current->process, async, SYNCHRONIZE, 0 ))) + set_error( STATUS_PENDING ); + return handle; +} + static obj_handle_t pipe_server_flush( struct fd *fd, struct async *async, int blocking ) { struct pipe_server *server = get_fd_user( fd ); - obj_handle_t handle = 0; + obj_handle_t handle; if (!server || server->state != ps_connected_server) return 0; if (!pipe_data_remaining( server )) return 0; - if (fd_queue_async( server->pipe_end.fd, async, ASYNC_TYPE_WAIT )) - { - /* there's no unix way to be alerted when a pipe becomes empty, so resort to polling */ - if (!server->flush_poll) - server->flush_poll = add_timeout_user( -TICKS_PER_SEC / 10, check_flushed, server ); - if (blocking) handle = alloc_handle( current->process, async, SYNCHRONIZE, 0 ); - set_error( STATUS_PENDING ); - } + handle = pipe_end_flush( &server->pipe_end, async, blocking ); + + /* there's no unix way to be alerted when a pipe becomes empty, so resort to polling */ + if (handle && !server->flush_poll) + server->flush_poll = add_timeout_user( -TICKS_PER_SEC / 10, check_flushed, server ); return handle; }