<div dir="ltr"><div><div><div>Yes, in wayland-client it is used this way. wl_connection_read returns number of bytes buffered in connection after reading (which should be positive value if reading was OK), otherwise it returns return value of recvmsg, which allows to distinguish between error and hangup (-1 and  0). What I was wondering about is if it can happen that recvmsg will contain only control data (fds). In that case the wl_connection_read would return 0 because the size of connection's buffer would be unchanged. So far I looked into it it seems this case is not possible, so this patch is:<br><br></div>Reviewed-by: Marek Chalupa <<a href="mailto:mchqwerty@gmail.com">mchqwerty@gmail.com</a>><br><br></div>Regards,<br></div>Marek<br></div><div class="gmail_extra"><br><div class="gmail_quote">On 6 October 2014 02:38, Jason Ekstrand <span dir="ltr"><<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Sun, Oct 5, 2014 at 2:23 PM, Karsten Otto <span dir="ltr"><<a href="mailto:karsten.otto@posteo.de" target="_blank">karsten.otto@posteo.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Am 29.09.2014 um 06:31 schrieb Jason Ekstrand <<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>>:<br>
<span><br>
><br>
> On Sep 28, 2014 11:49 AM, "Karsten Otto" <<a href="mailto:karsten.otto@posteo.de" target="_blank">karsten.otto@posteo.de</a>> wrote:<br>
> ><br>
> > From: Philip Withnall <<a href="mailto:philip@tecnocode.co.uk" target="_blank">philip@tecnocode.co.uk</a>><br>
> ><br>
> > This happens if the socket has been gracefully closed.<br>
> ><br>
> > [KAO: It prevents a potential infinite loop when using a different<br>
> > event handling mechanism than epoll, if said mechanism cannot<br>
> > distinguish EOF from regular read (e.g. select).]<br>
> > ---<br>
> >  src/wayland-server.c | 2 +-<br>
> >  1 file changed, 1 insertion(+), 1 deletion(-)<br>
> ><br>
> > diff --git a/src/wayland-server.c b/src/wayland-server.c<br>
> > index 674aeca..85741cb 100644<br>
> > --- a/src/wayland-server.c<br>
> > +++ b/src/wayland-server.c<br>
> > @@ -260,7 +260,7 @@ wl_client_connection_data(int fd, uint32_t mask, void *data)<br>
> >         len = 0;<br>
> >         if (mask & WL_EVENT_READABLE) {<br>
> >                 len = wl_connection_read(connection);<br>
> > -               if (len < 0 && errno != EAGAIN) {<br>
> > +               if (len == 0 || (len < 0 && errno != EAGAIN)) {<br>
> >                         wl_client_destroy(client);<br>
> >                         return 1;<br>
><br>
> It seems to me as if we should push this up the pipe to wl_connection_read so we fix it server-side too.<br>
><br>
</span>What do you mean? Calling wl_client_destroy within wl_client_read? Or making sure the connection is properly disposed of in both client and server code?<br>
<br>
Regarding the first, you would have to pass the wl_client reference to the read function, which would mix API layers unnecessarily. wl_client_read is basically just a convenient wrapper around recvmsg, so it should expose the same result semantics of >0 (OK), == 0 (EOF), and <0 (error), as it already does. It is up to the caller to handle the cases, if only to provide different log messages for error and EOF.<br>
<br>
Regarding the second, wl_connection_read is part of the wayland private/internal API, and only used in two places: wayland-client.c, which already handles EOF in an appropriate manner, and wayland-server.c, where the proposed patch handles the missing case as well. If anybody else needs to use wl_connection_read within the wayland libraries in the future, they are hopefully aware of the recv result semantics. If necessary, maybe add some documentation to wayland-private.h.<br></blockquote><div><br></div></div></div><div>What I meant was to just make wl_connection_read return something consistent (< 0 on EOF).  That said, if we're doing it this way in wayland-client, then I'm fine with it.  I didn't actually go look.<span class="HOEnZb"><font color="#888888"><br></font></span></div><span class="HOEnZb"><font color="#888888"><div>--Jason Ekstrand<br></div></font></span><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div><br>
> >                 }<br>
> > --<br>
> > 1.9.1<br>
> ><br>
> > _______________________________________________<br>
> > wayland-devel mailing list<br>
> > <a href="mailto:wayland-devel@lists.freedesktop.org" target="_blank">wayland-devel@lists.freedesktop.org</a><br>
> > <a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
<br>
</div></div></blockquote></span></div><br></div></div>
<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" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
<br></blockquote></div><br></div>