What exactly triggers creation of a new client in Wayland server

Kristian Høgsberg krh at bitplanet.net
Tue Jan 25 13:08:36 PST 2011


On Tue, Jan 25, 2011 at 4:02 PM, Zan Dobersek <zandobersek at gmail.com> wrote:
> Thanks for the reply.
> The following is what pushed me into researching the problem - I've created
> a test application that sets up a display and tries to create a client that
> connects to that display, but the client does not connect.
> Just as in compositor, I create a wl_display, add a socket to it and run the
> wayland event loop (through wl_display_run). I add a timer that sets off in
> ~2 seconds and sets up the client.
> Setting up the client starts as usual, calling wl_display_connect to connect
> to the display via socket. Then a listener for events is set up and the
> client enters the iteration to get all the events.
> The problem is that apparently when server and client are both living in the
> same program, socket_data doesn't get called because the client enters the
> iteration 'too soon' and then enters an infinite loop in wl_connection_data
> where client is waiting for data but it never receives any. Because
> socket_data doesn't get called, a client does not get created on server side
> and no events are passed onto it.
> But if I add another timer that puts off the iteration for one second,
> socket_data does get called and a client is created and is capable of
> receiving data.

Oh heh, client and server in the same process isn't really supported.
It may work, but you'll need to integrate the client socket into the
mainloop, and even then I'm not sure that it will work.  The Wayland
on Wayland compositor is a client of an existing Wayland server and a
server to its clients, but it doesn't connect to itself as a client.
But you can look at the last few lines in wayland_compositor_create()
to see how to get the fd from a client connection and then add it to
the mainloop of a server.

What are you trying to do?

Kristian

> Any ideas?
> Regards,
> Zan Dobersek
> On Tue, Jan 18, 2011 at 10:51 PM, Marty Jack <martyj19 at comcast.net> wrote:
>>
>> You have it right.
>>
>> When a client does a connect on a socket that another process is listening
>> to (the listen is at line 692), this makes the other end get a "readable" on
>> its end of the socket.  You then do an accept, which gives you a new fd for
>> your end of the connection.  You then have a bidirectional path between the
>> client's end and the compositor's end.  If you write data down one end, it
>> is readable at the other, and vice versa.
>>
>> In this case it is what is called a "UNIX domain socket", which is
>> represented by an entry in the file system.
>>
>> man 2 listen, man 2 accept, man 7 unix, any tutorial on networking
>>
>> On 01/18/2011 04:15 PM, Zan Dobersek wrote:
>> > Greetings,
>> >
>> > I'm wondering what exactly sets off the socket_data function in
>> > wayland/wayland-server.c at approximate line 640. I can see that we add a
>> > file descriptor object of our socket to the main loop in
>> > wl_display_add_socket that uses socket_data as the callback function when a
>> > client connects to that socket. Subsequently, we accept the connection in
>> > socket_data and create a new client.
>> >
>> > So, what is it in client's code that causes socket_data to be called? Is
>> > it just the mere connect() call to establish a connection through that
>> > socket or is it anything more complex that I have missed?
>> >
>> > My knowledge of sockets is quite basic, so I would be happy if someone
>> > would clarify how exactly this bit of code is executed.
>> >
>> > Regards,
>> >
>> > Zan Dobersek
>> >
>> >
>> >
>> > _______________________________________________
>> > wayland-devel mailing list
>> > wayland-devel at lists.freedesktop.org
>> > http://lists.freedesktop.org/mailman/listinfo/wayland-devel
>> _______________________________________________
>> wayland-devel mailing list
>> wayland-devel at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
>
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
>
>


More information about the wayland-devel mailing list