<div dir="ltr"><div><div>Would it make sense for wl_display_flush() to do this always? Ie it will never return EAGAIN. Then if needed make the non-blocking version be a new call.<br><br><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 14, 2016 at 6:40 PM, Jonas Ådahl <span dir="ltr"><<a href="mailto:jadahl@gmail.com" target="_blank">jadahl@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Fri, Jan 15, 2016 at 12:12:09AM +0000, Auke Booij wrote:<br>
> On 12 January 2016 at 04:31, Jonas Ådahl <<a href="mailto:jadahl@gmail.com">jadahl@gmail.com</a>> wrote:<br>
> > wl_display_flush() may fail with EAGAIN which means that not all data<br>
> > waiting in the buffer has been flushed. We later block until there<br>
><br>
> + is<br>
<br>
</span>Fixed locally.<br>
<div><div class="h5"><br>
><br>
> > data to read, which could mean that we block on input from the<br>
> > compositor without having sent out all data from the client. Avoid this<br>
> > by fully flushing the socket before starting to wait.<br>
> ><br>
> > Signed-off-by: Jonas Ådahl <<a href="mailto:jadahl@gmail.com">jadahl@gmail.com</a>><br>
> > ---<br>
> > src/wayland-client.c | 39 +++++++++++++++++++++++++++++----------<br>
> > 1 file changed, 29 insertions(+), 10 deletions(-)<br>
> ><br>
> > diff --git a/src/wayland-client.c b/src/wayland-client.c<br>
> > index 8bf6124..f47e395 100644<br>
> > --- a/src/wayland-client.c<br>
> > +++ b/src/wayland-client.c<br>
> > @@ -1442,6 +1442,21 @@ wl_display_cancel_read(struct wl_display *display)<br>
> > pthread_mutex_unlock(&display->mutex);<br>
> > }<br>
> ><br>
> > +static int<br>
> > +wl_display_poll(struct wl_display *display, short int events)<br>
> > +{<br>
> > + int ret;<br>
> > + struct pollfd pfd[2];<br>
><br>
> why 2? why an array at all? why not just<br>
><br>
> struct pollfd pfd;<br>
> pfd.fd = display->fd;<br>
> pfd.events = events;<br>
> do {<br>
> poll(&pfd, 1, -1);<br>
> } while (blabla);<br>
><br>
> (i understand this was in the original as well and you're simply<br>
> moving code around)<br>
<br>
</div></div>The git history doesn't provide an explanation so I guess it is just a<br>
mistake. I'll change the 2 to a 1 before pushing.<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
Jonas<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
><br>
> > +<br>
> > + pfd[0].fd = display->fd;<br>
> > + pfd[0].events = events;<br>
> > + do {<br>
> > + ret = poll(pfd, 1, -1);<br>
> > + } while (ret == -1 && errno == EINTR);<br>
> > +<br>
> > + return ret;<br>
> > +}<br>
> > +<br>
> > /** Dispatch events in an event queue<br>
> > *<br>
> > * \param display The display context object<br>
> > @@ -1485,27 +1500,31 @@ WL_EXPORT int<br>
> > wl_display_dispatch_queue(struct wl_display *display,<br>
> > struct wl_event_queue *queue)<br>
> > {<br>
> > - struct pollfd pfd[2];<br>
> > int ret;<br>
> ><br>
> > if (wl_display_prepare_read_queue(display, queue) == -1)<br>
> > return wl_display_dispatch_queue_pending(display, queue);<br>
> ><br>
> > + while (true) {<br>
> > + ret = wl_display_flush(display);<br>
> > + if (ret == -1 && errno == EAGAIN) {<br>
> > + if (wl_display_poll(display, POLLOUT) == -1) {<br>
> > + wl_display_cancel_read(display);<br>
> > + return -1;<br>
> > + }<br>
> > + } else {<br>
> > + break;<br>
> > + }<br>
> > + }<br>
> > +<br>
> > /* Don't stop if flushing hits an EPIPE; continue so we can read any<br>
> > * protocol error that may have triggered it. */<br>
> > - ret = wl_display_flush(display);<br>
> > - if (ret < 0 && errno != EAGAIN && errno != EPIPE) {<br>
> > + if (ret < 0 && errno != EPIPE) {<br>
> > wl_display_cancel_read(display);<br>
> > return -1;<br>
> > }<br>
> ><br>
> > - pfd[0].fd = display->fd;<br>
> > - pfd[0].events = POLLIN;<br>
> > - do {<br>
> > - ret = poll(pfd, 1, -1);<br>
> > - } while (ret == -1 && errno == EINTR);<br>
> > -<br>
> > - if (ret == -1) {<br>
> > + if (wl_display_poll(display, POLLIN) == -1) {<br>
> > wl_display_cancel_read(display);<br>
> > return -1;<br>
> > }<br>
> > --<br>
> > 2.4.3<br>
> ><br>
> > _______________________________________________<br>
> > wayland-devel mailing list<br>
> > <a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a><br>
> > <a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel" rel="noreferrer" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
_______________________________________________<br>
wayland-devel mailing list<br>
<a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel" rel="noreferrer" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
</div></div></blockquote></div><br></div>