Commit Graph

56 Commits

Author SHA1 Message Date
Keith Packard e7aa524bcb Switch to using the CMSG_* macros for FD passing
Use these instead of computing the values directly so that it might
work on BSD or other non-Linux systems

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
(cherry picked from commit 83f28ef865)
2013-11-07 20:26:19 -08:00
Keith Packard 568cf48f00 Add event queue splitting
This allows apps to peel off certain XGE events into separate queues
for custom handling. Designed to support the Present extension

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-By: Uli Schlachter <psychon@znc.in>
2013-11-07 13:32:46 -08:00
Keith Packard bbe7f95e07 Add support for receiving fds in replies
Requests signal which replies will have fds, and the replies report
how many fds they expect in byte 1.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-By: Uli Schlachter <psychon@znc.in>
2013-11-07 13:32:46 -08:00
Keith Packard aa6ac19ff4 Add xcb_send_fd API
This uses sendmsg to transmit file descriptors from the application to
the X server

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-By: Uli Schlachter <psychon@znc.in>
2013-11-07 13:32:20 -08:00
Arvind Umrao 769acff0da Added more error states and removed global error_connection
Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=41443
Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=42304

I have added more xcb connection error states at xcb.h header.
Also I have removed global error_connection variable, and added
an interface that returns connection error state.

TBD:
I will segregate errors states in a separate header file and try to
provide more precise error states, in future. Also I will give patch
for libX11, in that patch xcb_connection_t::has_error will be passed
to default io handler of libX11. This value can then be used for
displaying error messages.

Reviewed-by: Rami Ylimäki <rami.ylimaki@vincit.fi>
Reviewed-by: Uli Schlachter <psychon@znc.in>
Signed-off-by: Arvind Umrao <arvind.umrao@oracle.com>
2012-01-11 18:01:29 +01:00
Jamey Sharp e300ee4920 Revert "Introduce xcb_wait_for_event_until, for consuming responses in wire-order."
This function was intended to allow libX11 to fix a multi-threaded hang,
but the corresponding libX11 patch caused single-threaded apps to spin
sometimes. Since I've retracted that patch, this patch has no users and
shouldn't go into a release unless/until that changes.

This reverts commit 2415c11dec.

Conflicts:

	src/xcb.h
	src/xcb_in.c

Signed-off-by: Jamey Sharp <jamey@minilop.net>
2011-04-12 13:11:48 -07:00
Jamey Sharp 2415c11dec Introduce xcb_wait_for_event_until, for consuming responses in wire-order.
Signed-off-by: Jamey Sharp <jamey@minilop.net>
Reviewed-by: Josh Triplett <josh@freedesktop.org>
2011-03-18 21:59:47 -07:00
Jamey Sharp ed37b08751 xcb_in: Use 64-bit sequence numbers internally everywhere.
Widen sequence numbers on entry to those public APIs that still take
32-bit sequence numbers.

Signed-off-by: Jamey Sharp <jamey@minilop.net>
2010-10-09 17:13:45 -07:00
Jamey Sharp 3a74b5e7a1 xcb_request_check: Hold the I/O lock while deciding to sync.
Signed-off-by: Jamey Sharp <jamey@minilop.net>
2010-10-09 12:37:48 -07:00
Josh Triplett 1c4717de36 Allow disconnecting connections that are in error state.
In support of this, consolidate the two static error_connection
definitions into one so we don't try to free the static out-of-memory
error_connection.

Commit by Josh Triplett and Jamey Sharp.

Signed-off-by: Josh Triplett <josh@joshtriplett.org>
Signed-off-by: Jamey Sharp <jamey@minilop.net>
2010-09-19 20:38:06 +02:00
Jamey Sharp b0525e2423 Always wake up readers after writing.
Since writers must make sure they read as well, threads may have gone to
sleep waiting for the opportunity to read. The writer must wake up one
of those readers or the application can hang.

Signed-off-by: Jamey Sharp <jamey@minilop.net>
Reviewed-by: Josh Triplett <josh@freedesktop.org>
2010-04-17 18:20:41 -07:00
Jamey Sharp 6dd8228a13 Delete a useless level of indirection from _xcb_out_send's parameters.
_xcb_out_send needs _xcb_conn_wait to store back its progress so it can
be reinvoked to pick up where it left off---but then _xcb_out_send
guarantees that it leaves either an empty output vector or a shut-down
connection, so *its* callers never care how much progress was made.

Signed-off-by: Jamey Sharp <jamey@minilop.net>
Reviewed-by: Josh Triplett <josh@freedesktop.org>
2010-04-17 18:20:40 -07:00
Julien Danjou f0b2981974 auth: use snprintf() return value
That save us from a strlen().

Signed-off-by: Julien Danjou <julien@danjou.info>
2009-04-10 09:59:49 +02:00
Josh Triplett fa452cc9b2 Support handing off socket write permission to external code.
Libraries like Xlib, some XCB language bindings, and potentially others
have a common problem: they want to share the X connection with XCB. This
requires coordination of request sequence numbers.  Previously, XCB had an
Xlib-specific lock, and allowed Xlib to block XCB from making requests.
Now we've replaced that lock with a handoff mechanism, xcb_take_socket,
allowing external code to ask XCB for permission to take over the write
side of the socket and send raw data with xcb_writev.  The caller of
xcb_take_socket must supply a callback which XCB can call when it wants
the write side of the socket back to make a request.  This callback
synchronizes with the external socket owner, flushes any output queues if
appropriate, and then returns the sequence number of the last request sent
over the socket.

Commit by Josh Triplett and Jamey Sharp.
Handoff mechanism inspired by Keith Packard.
2008-10-29 15:40:41 -07:00
Jamey Sharp baff35a04b Track 64-bit sequence numbers internally.
External APIs that used 32-bit sequence numbers continue to do so.

Commit by Josh Triplett and Jamey Sharp.
2008-10-29 15:40:41 -07:00
Jamey Sharp 059ca642c7 Inline _xcb_lock_io, _xcb_unlock_io, and _xcb_wait_io.
These functions are once again a single pthread call, so just make that
call directly.
2008-10-29 15:40:41 -07:00
Jamey Sharp d989656cde Remove libxcb-xlib and xcbxlib.h. 2008-10-29 15:40:04 -07:00
Julien Danjou cebd482a20 allow compile-time setting for XCB queue buffer size
Signed-off-by: Julien Danjou <julien@danjou.info>
2008-10-14 20:38:47 +02:00
Jamey Sharp f6b75d6090 Factor pthread_cond_wait(iolock) to _xcb_wait_io.
This parallels the _xcb_lock_io and _xcb_unlock_io factoring.
2007-10-28 11:56:08 -07:00
Jamey Sharp 4d828c5eba Don't abort() on locking assertions if LIBXCB_ALLOW_SLOPPY_LOCK is set.
But do still print a full backtrace, on platforms where that's
supported.

This commit follows the spirit of Novell's libxcb-sloppy-lock.diff.

I strongly opposed proposals like this one for a long time. Originally I
had a very good reason: libX11, when compiled to use XCB, would crash
soon after a locking correctness violation, so it was better to have an
informative assert failure than a mystifying crash soon after.

It took some time for me to realize that I'd changed the libX11
implementation (for unrelated reasons) so that it could survive most
invalid locking situations, as long as it wasn't actually being used
from multiple threads concurrently.

The other thing that has changed is that most of the code with incorrect
locking has now been fixed. The value of the assert is accordingly
lower.

However, remaining broken callers do need to be fixed. That's why libXCB
will still noisily print a stacktrace (if possible) on each assertion
failure, even when assert isn't actually invoked to abort() the program;
and that's why aborting is still default. This environment variable is
provided only for use as a temporary workaround for broken applications.

Signed-off-by: Jamey Sharp <jamey@minilop.net>
Acked-by: Josh Triplett <josh@freedesktop.org>
2007-10-23 11:44:20 -07:00
Josh Triplett d6abe93b06 Refactor auth code to get display number from xcb_connect
Change xcb_connect to pass the display number to _xcb_get_auth_info, which
passes it to get_authptr.  This allows get_authptr to stop hacking the display
number out of the sockaddrs of various address families, such as
port - X_TCP_PORT, or the number after the last X in the UNIX socket path. This
also removes a portability bug introduced during the IPv6 changes: relying on
'\0'-termination of the UNIX socket path in a sockaddr_un.

Commit by Jamey Sharp and Josh Triplett.
2006-11-20 23:28:03 -08:00
Jamey Sharp da4d56ef5a Provide xcb_prefetch_maximum_request_length counterpart to xcb_get_maximum_request_length. 2006-11-18 22:38:42 -08:00
Jamey Sharp 40589db812 Add xcb_xlib_lock and xcb_xlib_unlock, a special-purpose two-level recursive lock just for libX11. 2006-10-04 15:01:00 -07:00
Jamey Sharp 57b0cd8fea Factor out pthread_mutex_lock and unlock calls for the iolock. 2006-10-04 14:52:49 -07:00
Josh Triplett a3bd6f4760 The Great XCB Renaming
Rename API to follow a new naming convention:
* XCB_CONSTANTS_UPPERCASE_WITH_UNDERSCORES
* xcb_functions_lowercase_with_underscores
* xcb_types_lowercase_with_underscores_and_suffix_t
* expand all abbreviations like "req", "rep", and "iter"

Word boundaries for the names in the protocol descriptions fall:
* Wherever the protocol descriptions already have an underscore
* Between a lowercase letter and a subsequent uppercase letter
* Before the last uppercase letter in a string of uppercase letters followed
  by a lowercase letter (such as in LSBFirst between LSB and First)
* Before and after a string of digits (with exceptions for sized types like
  xcb_char2b_t and xcb_glx_float32_t to match the stdint.h convention)

Also fix up some particular naming issues:
* Rename shape_op and shape_kind to drop the "shape_" prefix, since otherwise
  these types end up as xcb_shape_shape_{op,kind}_t.
* Remove leading underscores from enums in the GLX protocol description,
  previously needed to ensure a word separator, but now redundant.

This renaming breaks code written for the previous API naming convention.  The
scripts in XCB's tools directory will convert code written for the old API to
use the new API; they work well enough that we used them to convert the
non-program-generated code in XCB, and when run on the old program-generated
code, they almost exactly reproduce the new program-generated code (modulo
whitespace and bugs in the old code generator).

Authors: Vincent Torri, Thomas Hunger, Josh Triplett
2006-09-23 12:22:22 -07:00
Jamey Sharp 79e3227022 Add a private connection shutdown method for error cases. 2006-09-21 15:31:14 -07:00
Jamey Sharp ac17ae62fe Provide a "has error" property for XCBConnection. 2006-09-21 15:17:18 -07:00
Keith Packard db2504130b Switch sequence comparisons to handle 32-bit sequence number wrap.
Create a macro, XCB_SEQUENCE_COMPARE, that accepts two sequence numbers and
a comparison operator and correctly handles 32-bit wrap around.
Rewrite all ordered sequence number comparisons to use this macro.
Also, caught one error where a sequence was stored in a signed int variable.
Push out a GetInputFocus request when the sequence number does wrap at 32
bits so that applications cannot see sequence 0 (as that is an error
indicator).
2006-07-01 00:16:07 -07:00
Jamey Sharp dd932e025b Rename ConnSetup* to Setup*, Setup*Rep to Setup*, and SetupSuccess* to Setup*. Provide deprecated backwards-compatability functions and typedefs for the old names, to be removed before 1.0. 2006-04-26 23:19:16 -07:00
Ian Osgood be1302b6ef Remove last deprecation warning. 2006-03-13 10:36:13 -08:00
Jamey Sharp b83f18a4cc Only _xcb_conn_wait calls _xcb_out_write now, so move it to xcb_conn.c and make it static. 2006-03-12 13:20:29 -08:00
Jamey Sharp fb61c94d68 Remove c->out.vec. Pass iovecs directly down the call tree. Add _xcb_out_flush_to, refactor other functions, make write_block static. 2006-03-12 12:40:34 -08:00
Jamey Sharp 83e652f566 Move c->out.vec refs out of _xcb_conn_wait up to _xcb_out_flush. 2006-03-09 00:02:42 -08:00
Jamey Sharp 621f891c49 Move c->out.vec refs out of _xcb_out_write up to _xcb_conn_wait. 2006-03-08 14:21:16 -08:00
TORRI Vincent 522a6e0eac Use the GCC 4 visibility extension to mark everything in xcbint.h hidden. 2006-03-07 10:25:23 -08:00
Jamey Sharp e5458e477d Implement provably-correct sequence wrap handling. Add flag XCB_REQUEST_DISCARD_REPLY. 2006-03-05 00:20:50 -08:00
Jamey Sharp ed823bf651 Separate notion of request-completed from current-request, and mark requests completed more aggressively. Detects some usage errors that are otherwise undetectable. 2006-03-02 13:49:00 -08:00
Jamey Sharp 8ab4dcde9d _xcb_list is no longer used, so remove it. Simplify _xcb_map. 2006-02-27 02:14:48 -08:00
Jamey Sharp 76ad79a7ad Replace readers generic list with hand-written typesafe version. 2006-02-27 01:43:07 -08:00
Jamey Sharp 50acfeae36 Delete unused xcb_list functions and refactor others. 2006-02-26 23:43:44 -08:00
Jamey Sharp 86ce18c22c Replace current_reply generic queue with hand-written version. No generic queues remain so delete their implementation. 2006-02-26 22:58:17 -08:00
Jamey Sharp 0f130b4d94 Replace events generic queue with hand-written typesafe version. 2006-02-26 18:28:50 -08:00
Jamey Sharp ff7b6c9124 API/ABI break: Add flags to XCBSendRequest, first for error-checked requests.
There's no more race condition between event and reply handling.
The *RequestBlind and *RequestChecked functions are not yet implemented.
2006-02-26 15:45:08 -08:00
Jamey Sharp 7875040fa1 Replace pending_replies generic queue with a hand-implemented typesafe version. 2006-02-26 02:00:03 -08:00
Jamey Sharp a1eff0c49a Replace my old generic map ADT with a growable array for the extension cache. 2006-02-26 01:27:01 -08:00
Jamey Sharp bae98d3604 Move _xcb_set_fd_flags to xcb_conn.c and make it static. xcb_util.c now has only public functions. 2006-02-24 01:50:48 -08:00
Jamey Sharp 67b2649dc4 Move _xcb_read_block to xcb_in.c and make it static. Change calls in xcb_conn.c to _xcb_in_read_block instead. 2006-02-24 01:40:45 -08:00
Jamey Sharp 838317f4d3 Remove XCB_CEIL and use a simpler definition for XCB_PAD. 2006-02-24 01:17:03 -08:00
Jamey Sharp 1b50d2ee1e Quit using "-include config.h": use #ifdef HAVE_CONFIG_H etc. like everyone else. 2006-02-24 01:04:48 -08:00
Jamey Sharp 3f8d0bd532 Move _xcb_readn to xcb_in.c and make it static. Minor change to _xcb_read_block to not depend on _xcb_readn. 2006-02-24 00:48:18 -08:00