From: Ben Pfaff Date: Thu, 12 Nov 2009 20:52:12 +0000 (-0800) Subject: stream: New function pstream_accept_block(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8d76bcca4daa3a65a233c45bf6ecd93ace1dfe9e;p=openvswitch stream: New function pstream_accept_block(). --- 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) { diff --git a/lib/stream.h b/lib/stream.h index 76c9e6c6..7a62a5a3 100644 --- a/lib/stream.h +++ b/lib/stream.h @@ -57,6 +57,7 @@ int pstream_open(const char *name, struct pstream **); const char *pstream_get_name(const struct pstream *); void pstream_close(struct pstream *); int pstream_accept(struct pstream *, struct stream **); +int pstream_accept_block(struct pstream *, struct stream **); void pstream_wait(struct pstream *); #endif /* stream.h */