summaryrefslogtreecommitdiff
path: root/src/wayland-client.c
AgeCommit message (Collapse)AuthorFilesLines
2012-11-30client: Add \since tag for wl_display_dispatch_queue_pending() documentationKristian Høgsberg1-0/+1
2012-11-27client: Don't cancel a roundtrip when any event is receivedJonas Ådahl1-1/+4
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>
2012-11-23doc: Fix typosTiago Vignatti1-2/+2
Signed-off-by: Tiago Vignatti <tiago.vignatti@intel.com>
2012-11-23client: Add an entry point for dispatching a queue without blockingAnder Conselvan de Oliveira1-0/+19
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.
2012-11-21debug: Allow WAYLAND_DEBUG=server/client for server/client side only debugKristian Høgsberg1-1/+1
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.
2012-11-14client: Fix source comment typosMartin Olsson1-3/+3
2012-11-05client: Keep track of proxy validity and number of reference holdersJonas Ådahl1-20/+108
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>
2012-10-19doc: Clarify documentation about dispatching event queuesAnder Conselvan de Oliveira1-2/+56
Clarify on what cases each of the dispatching functions may block, what is the main thread and add some real world examples.
2012-10-17doc: Update wl_display_get_error() documentationAnder Conselvan de Oliveira1-2/+8
2012-10-16doc: Add doxygen documentation to wl_display_get_error()Ander Conselvan de Oliveira1-0/+7
2012-10-16doc: Document change of return value of dispatch functionsAnder Conselvan de Oliveira1-2/+3
2012-10-16doc: Document the restriction of destroying queues before the displayAnder Conselvan de Oliveira1-0/+4
2012-10-16doc: Put wl_display_flush() documentation in the right placeAnder Conselvan de Oliveira1-12/+12
It seems a rebase error caused it to end up in the wrong place.
2012-10-15wayland-client: forward fatal errors to callerDavid Herrmann1-19/+80
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>
2012-10-15wayland: Take ownership of fd in wl_display_connect_to_fd()Kristian Høgsberg1-11/+9
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.
2012-10-15wayland-client: link all event-queues of each display into a listDavid Herrmann1-3/+17
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>
2012-10-15wayland-client: add wl_display_get_error()David Herrmann1-3/+36
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>
2012-10-15doc: Improve libwayland-client doxygen documentationAnder Conselvan de Oliveira1-7/+46
Document wl_proxy, wl_display and wl_event_queue classes and add a description to all public entry points. Also fix some typos.
2012-10-15doc: Add some doxygen documentation to wayland-client entry pointsAnder Conselvan de Oliveira1-1/+169
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>
2012-10-15client: Return number of events dispatched from dispatch functionsKristian Høgsberg1-3/+3
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.
2012-10-15client: Add wl_display_dispatch_pending() for dispatching without readingKristian Høgsberg1-6/+21
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.
2012-10-11client: Discard proxies with no implementation at dispatch timeKristian Høgsberg1-2/+3
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.
2012-10-11client: Don't forget to init and destroy mutexKristian Høgsberg1-0/+2
These chunks were dropped at some point, thanks to David Herrmann for spotting the omission.
2012-10-11client: Fix double locking bugAnder Conselvan de Oliveira1-3/+2
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().
2012-10-10connection: Move object lookup out of wl_connection_demarshal()Kristian Høgsberg1-6/+13
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.
2012-10-10Split the global registry into its own wl_registry objectKristian Høgsberg1-110/+0
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.
2012-10-10scanner: Generate client stubs for wl_display requestsKristian Høgsberg1-31/+0
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.
2012-10-10client: Add wl_event_queue for multi-thread dispatchingKristian Høgsberg1-35/+115
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.
2012-10-10client: Make wl_display thread safeKristian Høgsberg1-4/+42
Not all entry points are thread safe: global listeners and global lookup is still only main thread.
2012-10-10client: Split event handling into demarshal and dispatch stepsKristian Høgsberg1-20/+48
This lets us demarshal with a mutex held and then do dispatching after releasing the mutex.
2012-10-10Change filedescriptor API to be thread safeKristian Høgsberg1-48/+14
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.
2012-08-16client: Add wl_display_connect_to_fd() functionKristian Høgsberg1-27/+44
This lets us connect a display to an already existing socket fd.
2012-07-23More consistent ID printingDaniel Stone1-7/+7
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>
2012-07-23Make NEW_IDs nullableDaniel Stone1-5/+15
The connection-handling code already allows this, so make it legal in the protocol definition too. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-07-20wayland-client: Add missing newline from an error messageRobert Ancell1-1/+1
2012-06-30wayland-client: reject socket paths longer than 108 bytesDylan Noblesmith1-1/+13
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.
2012-06-28Allocate client proxy automatically for new objectsKristian Høgsberg1-1/+26
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.
2012-06-13connection: Always malloc closureKristian Høgsberg1-16/+14
This lets us allocate the closure just big enough and is a first step towards a message queue.
2012-06-06client: require XDG_RUNTIME_DIRPekka Paalanen1-8/+11
An arbitrary fallback to the current directory is only confusing. Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-05-31Wayland: loggingMartin Minarik1-0/+6
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.
2012-04-27Add wl_proxy_get_id()Kristian Høgsberg1-0/+6
2012-04-22connection: Move closure object out of wl_connectionKristian Høgsberg1-15/+16
2012-04-20os: wrap socket(SOCK_CLOEXEC) callsPekka Paalanen1-1/+2
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>
2012-04-11Switch protocol to using serial numbers for ordering events and requestsKristian Høgsberg1-1/+1
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.
2012-03-30Fix remaining signedness errorsKristian Høgsberg1-3/+3
We can change the data type for 'size' but we have to cast len to size_t for the comparisons with sizeof results.
2012-02-29Don't block when flushing a full protocol bufferKristian Høgsberg1-1/+4
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.
2012-02-28Allow update function to not be set in wl_display_get_fdSamuel Rødal1-1/+3
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.
2012-02-28Rename client side wl_display_destroy() to wl_display_disconnect()Samuel Rødal1-1/+1
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.
2012-02-09Drop warning when we receive an event for zombie objectsKristian Høgsberg1-1/+0
Business as usual, but the message is confusing.
2011-12-17Increase closure buffer size and fail gracefully for too big closures.Laszlo Agocs1-1/+6
Buffer size changed from 256 to 1024 bytes. Marshalling will now stop if the buffer is not big enough.