Maybe a patch will make it more clear (see attached).

Martin

On Sunday, May 18, 2014 2:02:15 PM UTC+2, Martin Sustrik wrote:
>
> Hi Saul,
>
> This is intended behavior. The "once" is related to polling for i/o. 
>> So the loop will block for i/o once. But X callbacks might be fired, 
>> if handles are ready or many sockets become readable, etc. 
>>
>
> Sure, but that's not what I've asked about.
>
> The question is rather whether the loop should behave the same whether the 
> event is retrieved from actual poll or queued from before (synchronous 
> replies for previous requests, AFAIU).
>
> I would say it should.
>
> Martin
>

-- 
You received this message because you are subscribed to the Google Groups 
"libuv" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/libuv.
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/unix/core.c b/src/unix/core.c
index 9680a2d..e046b11 100644
--- a/src/unix/core.c
+++ b/src/unix/core.c
@@ -70,7 +70,8 @@
 # endif
 #endif
 
-static void uv__run_pending(uv_loop_t* loop);
+/* Returns true if it processes at least one event, false otherwise. */
+static int uv__run_pending(uv_loop_t* loop);
 
 /* Verify that uv_buf_t is ABI-compatible with struct iovec. */
 STATIC_ASSERT(sizeof(uv_buf_t) == sizeof(struct iovec));
@@ -272,6 +273,7 @@ int uv_loop_alive(const uv_loop_t* loop) {
 
 int uv_run(uv_loop_t* loop, uv_run_mode mode) {
   int timeout;
+  int pending;
   int r;
 
   r = uv__loop_alive(loop);
@@ -285,7 +287,9 @@ int uv_run(uv_loop_t* loop, uv_run_mode mode) {
     uv__run_timers(loop);
     uv__run_idle(loop);
     uv__run_prepare(loop);
-    uv__run_pending(loop);
+    pending = uv__run_pending(loop);
+    if (mode == UV_RUN_ONCE && pending)
+        break;
 
     timeout = 0;
     if ((mode & UV_RUN_NOWAIT) == 0)
@@ -630,9 +634,10 @@ void uv_disable_stdio_inheritance(void) {
 }
 
 
-static void uv__run_pending(uv_loop_t* loop) {
+static int uv__run_pending(uv_loop_t* loop) {
   QUEUE* q;
   uv__io_t* w;
+  int res = !QUEUE_EMPTY(&loop->pending_queue);
 
   while (!QUEUE_EMPTY(&loop->pending_queue)) {
     q = QUEUE_HEAD(&loop->pending_queue);
@@ -642,6 +647,8 @@ static void uv__run_pending(uv_loop_t* loop) {
     w = QUEUE_DATA(q, uv__io_t, pending_queue);
     w->cb(loop, w, UV__POLLOUT);
   }
+
+  return res;
 }
 
 

Reply via email to