diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2020-06-27 01:12:14 +0200 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2020-06-27 01:12:14 +0200 |
commit | b290be35e0717ad68d9a851974e7fcfedc88c448 (patch) | |
tree | 766fa0c27633c44d8c740b38daa7253f186daf85 /libpipe | |
parent | b95271e96190f0b854b46c8d5b8aab1a812d35a8 (diff) | |
download | hurd-b290be35e0717ad68d9a851974e7fcfedc88c448.tar.gz hurd-b290be35e0717ad68d9a851974e7fcfedc88c448.tar.bz2 hurd-b290be35e0717ad68d9a851974e7fcfedc88c448.zip |
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.
Diffstat (limited to 'libpipe')
-rw-r--r-- | libpipe/pipe.c | 31 | ||||
-rw-r--r-- | libpipe/pipe.h | 4 |
2 files changed, 23 insertions, 12 deletions
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; diff --git a/libpipe/pipe.h b/libpipe/pipe.h index 040204d5..eda38d24 100644 --- a/libpipe/pipe.h +++ b/libpipe/pipe.h @@ -263,6 +263,10 @@ void _pipe_no_readers (struct pipe *pipe); should be locked. */ void _pipe_no_writers (struct pipe *pipe); +/* Take any actions necessary when PIPE's writer can proceed. + PIPE should be locked. */ +void _pipe_wake_writers (struct pipe *pipe); + extern void pipe_acquire_reader (struct pipe *pipe); extern void pipe_acquire_writer (struct pipe *pipe); |