Age | Commit message (Collapse) | Author | Files | Lines |
|
|
|
Since wl_display_dispatch() returns the number of processed events or -1
on error, only cancel the roundtrip if an -1 is returned.
This also fixes a potential memory corruption bug happening when
wl_display_roundtrip() does an early return and the callback later
writes to the then out of scope stack allocated `done' parameter.
Introduced by 33b7637b4500a682018b503837b8aca9afae36f2.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
|
|
Signed-off-by: Tiago Vignatti <tiago.vignatti@intel.com>
|
|
On the client side EGL, all the wl_buffer.release events need to be
processed before buffer allocation, otherwise a third buffer might
be allocated unnecessarily. However, the buffer allocation should
not block in the case no event was received. In order to do that, a
non-blocking queue dispatch function is needed.
|
|
By default the server will dump protocol for both the server and its
clients when run with WAYLAND_DEBUG=1. That's still the case, but it now
also understands WAYLAND_DEBUG=client or WAYLAND_DEBUG=server, which
will only enable debug dumping on either client or server side.
|
|
|
|
When events are queued, the associated proxy objects (target proxy and
potentially closure argument proxies) are verified being valid. However,
as any event may destroy some proxy object, validity needs to be
verified again before dispatching. Before this change this was done by
again looking up the object via the display object map, but that did not
work because a delete_id event could be dispatched out-of-order if it
was queued in another queue, causing the object map to either have a new
proxy object with the same id or none at all, had it been destroyed in
an earlier event in the queue.
Instead, make wl_proxy reference counted and increase the reference
counter of every object associated with an event when it is queued. In
wl_proxy_destroy() set a flag saying the proxy has been destroyed by the
application and only free the proxy if the reference counter reaches
zero after decreasing it.
Before dispatching, verify that a proxy object still is valid by
checking that the flag set in wl_proxy_destroy() has not been set. When
dequeuing the event, all associated proxy objects are dereferenced and
free:ed if the reference counter reaches zero. As proxy reference counter
is initiated to 1, when dispatching an event it can never reach zero
without having the destroyed flag set.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
|
|
Clarify on what cases each of the dispatching functions may block, what
is the main thread and add some real world examples.
|
|
|
|
|
|
|
|
|
|
It seems a rebase error caused it to end up in the wrong place.
|
|
If any callback or helper function fails with a fatal error, we now
set the last_error flag and prevent all further I/O on the wl_display. We
wake up all sleeping event-queues and notify the caller that they
should shutdown wl_display.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
|
|
This means we're free to close it when we want, which we'll use to wake
up the main thread if we hit an error in a different thread.
|
|
We need access to all event-queues of a single wl_display object. For
instance during connection-errors, we need to be able to wake up all event
queues. Otherwise, they will be stuck waiting for incoming events.
The API user is responsible to keep a wl_display object around until all
event-queues that were created on it are destroyed.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
|
|
A server may asynchronously send errors via wl_display.error() events.
Instead of aborting we now the a "last_error" flag inside of wl_display
objects. The user can retrieve these via wl_display_get_error().
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
|
|
Document wl_proxy, wl_display and wl_event_queue classes and add a
description to all public entry points. Also fix some typos.
|
|
Add some brief documentation for the public libwayland-client entry
points. This is by no means complete, some functions are still
undocumented and some might need extra information.
Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com>
Signed-off-by: Tiago Vignatti <tiago.vignatti@intel.com>
|
|
To let clients determine whether any events were dispatched, we return
the number of dispatched events. An event source with an event queue
(such as wl_display or an X connection) may queue up event as a result of
processing a different event source (data on a network socket, timerfd etc).
After dispatching data from fd (or just before blocking) we have to check
such event sources, which is what wl_event_source_check() is used for.
A checked event source will have its handler called with mask=0 just
before blocking. If any work is done in any of these handlers, we have
to check all the checked sources again, since the work could have queued up
events in a different source. This is why the event handlers must return
a positive number if events were handled. Which in turn is why we need
the wl_display dispatch functions to return that as well.
|
|
If the main thread ends up dispatching a non-main queue, and not in
a wl_display_dispatch() callback, we may queue up main queue events and read
all data from the socket fd. When we get back to the main loop, the
socket fd is no longer readable and nothing will trigger dispatching of
the queued up events.
The new function wl_display_dispatch_pending() will dispatch any pending
events, but not attempt to read from the socket. Clients that integrate
the wayland socket fd into a main loop should call
wl_display_dispatch_pending() and then wl_display_flush()
before going back to blocking in poll(2) or similar mechanism.
|
|
We need to queue up events even if a proxy doesn't have an implementation
(listener). In case of server created new objects, the client haven't
had a chance to set the listener when the first events to the new object
come in. So now we always queue up events and discard them at
dispatch time if they don't have a listener at that point.
|
|
These chunks were dropped at some point, thanks to David Herrmann for
spotting the omission.
|
|
The function wl_proxy_create_for_id() would try to acquire the display
lock, but the only call path leading to it would call it with the lock
already acquired.
This patch removes the attempt to acquire the lock and makes the
function static. It was exported before because client had to create
proxy's manually when the server sent a new object id, but since commit
9de9e39f [1] this is no longer necessary.
[1] commit 9de9e39f87adfce1ea9755e394928756254c0ba2
Author: Kristian Høgsberg <krh@bitplanet.net>
Date: Thu Jun 28 22:01:58 2012 -0400
Allocate client proxy automatically for new objects
v2: Change the right function. Previous patch changed wl_proxy_create()
instead of wl_proxy_create_for_id().
|
|
On the client side where we queue up multiple events before dispatching, we
need to look up the receiving proxy and argument proxies immediately before
calling the handler. Between queueing up multiple events and eventually
invoking the handler, previous handlers may have destroyed some of the
proxies.
|
|
The only way to make the global object listener interface thread safe is to
make it its own interface and make different listeners different wl_proxies.
The core of the problem is the callback we do when a global show up or
disappears, which we can't do with a lock held. On the other hand we can't
iterate the global list or the listener list without a lock held as new
globals or listeners may come and go during the iteration.
Making a copy of the list under the lock and then iterating after dropping
the lock wont work either. In case of the listener list, once we drop the
lock another thread may unregister a listener and destroy the callbackk
data, which means that when we eventually call that listener we'll pass it
free memory and break everything.
We did already solve the thread-safe callback problem, however. It's what
we do for all protocol events. So we can just make the global registry
functionality its own new interface and give each thread its own proxy.
That way, the thread will do its own callbacks (with no locks held) and
destroy the proxy when it's no longer interested in wl_registry events.
|
|
We used to special case this because of the untyped new-id argument in
the bind request. Now that the scanner can handle that, we can
remove the special case.
Switching to the generated stubs does bring an API change since we now
also take the interface version that the client expects as an argument.
Previously we would take this from the interface struct, but the
application may implement a lower version than what the interface struct
provides. To make sure we don't try to dispatch event the client
doesn't implement handlers for, we have to use a client supplied version
number.
|
|
This introduces wl_event_queue, which is what will make multi-threaded
wayland clients possible and useful. The driving use case is that of a
GL rendering thread that renders and calls eglSwapBuffer independently of
a "main thread" that owns the wl_display and handles input events and
everything else. In general, the EGL and GL APIs have a threading model
that requires the wayland client library to be usable from several threads.
Finally, the current callback model gets into trouble even in a single
threaded scenario: if we have to block in eglSwapBuffers, we may end up
doing unrelated callbacks from within EGL.
The wl_event_queue mechanism lets the application (or middleware such as
EGL or toolkits) assign a proxy to an event queue. Only events from objects
associated with the queue will be put in the queue, and conversely,
events from objects associated with the queue will not be queue up anywhere
else. The wl_display struct has a built-in event queue, which is considered
the main and default event queue. New proxies are associated with the
same queue as the object that created them (either the object that a
request with a new-id argument was sent to or the object that sent an
event with a new-id argument). A proxy can be moved to a different event
queue by calling wl_proxy_set_queue().
A subsystem, such as EGL, will then create its own event queue and associate
the objects it expects to receive events from with that queue. If EGL
needs to block and wait for a certain event, it can keep dispatching event
from its queue until that events comes in. This wont call out to unrelated
code with an EGL lock held. Similarly, we don't risk the main thread
handling an event from an EGL object and then calling into EGL from a
different thread without the lock held.
|
|
Not all entry points are thread safe: global listeners and global lookup
is still only main thread.
|
|
This lets us demarshal with a mutex held and then do dispatching after
releasing the mutex.
|
|
The update callback for the file descriptors was always a bit awkward and
un-intuitive. The idea was that whenever the protocol code needed to
write data to the fd it would call the 'update' function. This function
would adjust the mainloop so that it polls for POLLOUT on the fd so we
can eventually flush the data to the socket.
The problem is that in multi-threaded applications, any thread can issue
a request, which writes data to the output buffer and thus triggers the
update callback. Thus, we'll be calling out with the display mutex
held and may call from any thread.
The solution is to eliminate the udpate callback and just require that
the application or server flushes all connection buffers before blocking.
This turns out to be a simpler API, although we now require clients to
deal with EAGAIN and non-blocking writes. It also saves a few syscalls,
since the socket will be writable most of the time and most writes will
complete, so we avoid changing epoll to poll for POLLOUT, then write and
then change it back for each write.
|
|
This lets us connect a display to an already existing socket fd.
|
|
Use unsigned rather than signed for IDs, so they match up with what we
see in other prints.
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
|
|
The connection-handling code already allows this, so make it legal in
the protocol definition too.
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
|
|
|
|
Attempting to write anything longer into the embedded char
array would create a non-null-terminated string, and all
later reads would run off the end into invalid memory.
This is a hard limitation of AF_LOCAL/AF_UNIX sockets.
|
|
When the server send a new object ID, the client used to have to allocate
the proxy manually and without type-safety. We now allocate the proxy
in a client-side post-processing step on the incoming closure.
|
|
This lets us allocate the closure just big enough and is a first step towards
a message queue.
|
|
An arbitrary fallback to the current directory is only confusing.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
|
|
The core libwayland libraries should not handle logging, only passing
the error messages to subscribed functions.
An application linked to libwayland-server or libwayland-client
will be able to set own functions (one per library) to handle error
messages.
Change in this series: make the wl_log return int, because
of compatibility with printf. It will return the number of bytes logged.
|
|
|
|
|
|
Some system C libraries do not offer SOCK_CLOEXEC flag.
Add a new header for OS compatibility wrappers. Wrap socket() calls into
wl_os_socket_cloexec() which makes sure the O_CLOEXEC flag gets set on
the file descriptor.
On systems having SOCK_CLOEXEC this uses the old socket() call, and
falls back if it fails due to the flag (kernel not supporting it).
wayland-os.h is private and not exported.
Add close-on-exec tests for both normal and forced fallback paths.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
|
|
The wayland protocol, as X, uses timestamps to match up certain
requests with input events. The problem is that sometimes we need to
send out an event that doesn't have a corresponding timestamped input
event. For example, the pointer focus surface goes away and new
surface needs to receive a pointer enter event. These events are
normally timestamped with the evdev event timestamp, but in this case,
we don't have a evdev timestamp. So we have to go to gettimeofday (or
clock_gettime()) and then we don't know if it's coming from the same
time source etc.
However for all these cases we don't need a real time timestamp, we
just need a serial number that encodes the order of events inside the
server. So we introduce a serial number mechanism that we can use to
order events. We still need real-time timestamps for actual input
device events (motion, buttons, keys, touch), to be able to reason
about double-click speed and movement speed so events that correspond to user input carry both a serial number and a timestamp.
The serial number also give us a mechanism to key together events that
are "logically the same" such as a unicode event and a keycode event,
or a motion event and a relative event from a raw device.
|
|
We can change the data type for 'size' but we have to cast len to size_t
for the comparisons with sizeof results.
|
|
In case the client isn't responding, this will block the compositor.
Instead we flush with MSG_DONTWAIT, which lets us fill up the kernel buffer
as much as we can (after not returning EPOLLOUT anymore it still can take
80k more), and then disconnect the client if we get EAGAIN.
|
|
Ignore previous patch, here's the correct version.
From 4e1bedaaf05b576f5191f8fe3a34904ab9707414 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Samuel=20R=C3=B8dal?= <samuel.rodal@nokia.com>
Date: Mon, 27 Feb 2012 15:17:20 +0100
Subject: [PATCH] Allow update function to not be set in wl_display_get_fd
The same check is done in connection_update, and now with
wl_display_flush() there's less need for the client to need to know the
connection mask.
|
|
This avoids the clash with the wayland-server version with the same
name, and allows linking against both wayland-client and wayland-server
at the same time, which can be useful for unit testing purposes as
well as for nested compositing.
Without this there will be crashes as the wrong wl_display_destroy()
is called.
|
|
Business as usual, but the message is confusing.
|
|
Buffer size changed from 256 to 1024 bytes. Marshalling will now stop
if the buffer is not big enough.
|