diff options
author | Ben Pfaff <blp@nicira.com> | 2009-11-12 12:52:12 -0800 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2009-11-12 12:57:26 -0800 |
commit | 8d76bcca4daa3a65a233c45bf6ecd93ace1dfe9e (patch) | |
tree | aab96c9d7071a35dc1f8a84d9c6bd07dcf5e13e0 /lib/stream.c | |
parent | 3ed497fc10033c9857140270d60ef6aa2d7c0c08 (diff) |
stream: New function pstream_accept_block().
Diffstat (limited to 'lib/stream.c')
-rw-r--r-- | lib/stream.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/stream.c b/lib/stream.c index 1a0ea7ba..23b25f22 100644 --- a/lib/stream.c +++ b/lib/stream.c @@ -422,6 +422,27 @@ pstream_accept(struct pstream *pstream, struct stream **new_stream) return retval; } +/* Tries to accept a new connection on 'pstream'. If successful, stores the + * new connection in '*new_stream' and returns 0. Otherwise, returns a + * positive errno value. + * + * pstream_accept_block() blocks until a connection is ready or until an error + * occurs. It will not return EAGAIN. */ +int +pstream_accept_block(struct pstream *pstream, struct stream **new_stream) +{ + int error; + + while ((error = pstream_accept(pstream, new_stream)) == EAGAIN) { + pstream_wait(pstream); + poll_block(); + } + if (error) { + *new_stream = NULL; + } + return error; +} + void pstream_wait(struct pstream *pstream) { |