From b290be35e0717ad68d9a851974e7fcfedc88c448 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sat, 27 Jun 2020 01:12:14 +0200 Subject: pflocal: Add support for setsockopt(SO_{RECV,SND}BUF) Thanks Svante Signell for the initial patch. * libpipe/pipe.c (pipe_recv): Move writer wake code to... (_pipe_wake_writers): ... new function. * libpipe/pipe.h (_pipe_wake_writers): New prototype. * pflocal/sock.h (PFLOCAL_WRITE_LIMIT_MAX): New macro. * pflocal/socket.c (S_socket_setopt): Handle SO_RCVBUF and SO_SNDBUF cases. --- libpipe/pipe.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'libpipe/pipe.c') diff --git a/libpipe/pipe.c b/libpipe/pipe.c index 1d4f5cc0..8ffc56e9 100644 --- a/libpipe/pipe.c +++ b/libpipe/pipe.c @@ -200,6 +200,24 @@ void _pipe_no_writers (struct pipe *pipe) pthread_mutex_unlock (&pipe->lock); } } + +/* Take any actions necessary when PIPE's writer can proceed. + PIPE should be locked. */ +void _pipe_wake_writers (struct pipe *pipe) +{ + pthread_cond_broadcast (&pipe->pending_writes); + pthread_mutex_unlock (&pipe->lock); + + pthread_mutex_lock (&pipe->lock); /* Get back the lock on PIPE. */ + /* Only wakeup selects if there's still writing space available. */ + if (pipe_readable (pipe, 1) < pipe->write_limit) + { + pthread_cond_broadcast (&pipe->pending_write_selects); + pipe_select_cond_broadcast (pipe); + /* We leave PIPE locked here, assuming the caller will soon unlock + it and allow others access. */ + } +} /* Return when either RPIPE is available for reading (if SELECT_READ is set in *SELECT_TYPE), or WPIPE is available for writing (if select_write is @@ -474,18 +492,7 @@ pipe_recv (struct pipe *pipe, int noblock, unsigned *flags, void **source, timestamp (&pipe->read_time); /* And wakeup anyone that might be interested in it. */ - pthread_cond_broadcast (&pipe->pending_writes); - pthread_mutex_unlock (&pipe->lock); - - pthread_mutex_lock (&pipe->lock); /* Get back the lock on PIPE. */ - /* Only wakeup selects if there's still writing space available. */ - if (pipe_readable (pipe, 1) < pipe->write_limit) - { - pthread_cond_broadcast (&pipe->pending_write_selects); - pipe_select_cond_broadcast (pipe); - /* We leave PIPE locked here, assuming the caller will soon unlock - it and allow others access. */ - } + _pipe_wake_writers (pipe); } return err; -- cgit v1.2.3