X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=lib%2Fstream.c;h=23b25f22173b4ee4e5f41ce4fa71fb21a67fc39a;hb=6e79e2104c95e005e81a070053a3dc99a2bfde09;hp=1a0ea7ba7466699ca80f1318e16a963e8ad1277c;hpb=c34b65c731a1b6dae014efe8895141e5b2fe758a;p=openvswitch 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) {