C interface to the X Window System protocol, which replaces the traditional Xlib interface.
Go to file
Peter Harris 21414e7c44 Fix writev emulation on Windows
There are at least two bugs in the previous implementation:

- If an early iovec is partially written, there can be a gap of missing
  data (as a later iovec will be started before the early iovec is
  completed).
- If a late iovec returns WSAEWOULDBLOCK, *vector and *count are not
  updated, leading to a re-send of the entire request.

Move the *vector update into the send() loop to update piecemeal as
individual iovecs are sent.

Example program that demonstrates the issue (this program should run
forever after these bugs have been fixed):

#include <stdio.h>
#include <stdlib.h>
#include "xcb.h"

// Non-cryptographic random number generator from http://burtleburtle.net/bob/rand/smallprng.html
// because Microsoft's random number generators either have a too small RAND_MAX or are too slow
typedef struct ranctx { uint32_t a; uint32_t b; uint32_t c; uint32_t d; } ranctx;

static uint32_t ranval(ranctx *x);
static void raninit(ranctx *x, uint32_t seed);


#define MAX_PROP_LEN (128 * 1024)

int main(int argc, char *argv[]) {
    uint32_t seed = 0x12345678;
    if (argc > 1) {
        seed = strtoul(argv[1], NULL, 0);
    }
    ranctx ran;
    raninit(&ran, seed);

    xcb_connection_t *c = xcb_connect(NULL, NULL);
    if (!c || xcb_connection_has_error(c)) {
        printf("Cannot connect to $DISPLAY\n");
        return 1;
    }
    const xcb_setup_t *setup = xcb_get_setup(c);
    char *buf = malloc(MAX_PROP_LEN + 8); // plus a bit of slack so we can run random values off the end
    if (!buf) {
        printf("oom\n");
        return 1;
    }
    for (uint32_t i=0; i < (MAX_PROP_LEN + 3) / 4; i++) {
        ((uint32_t *)buf)[i] = ranval(&ran);
    }

    xcb_window_t win = xcb_generate_id(c);
    xcb_create_window(c, 0, win, xcb_setup_roots_iterator(setup).data[0].root, 0, 0, 1, 1, 0,
            XCB_WINDOW_CLASS_INPUT_ONLY, 0, 0, NULL);
    printf("Created window 0x%X\n", win);

    for (;;) {
        xcb_flush(c);
        xcb_generic_event_t *ev = xcb_poll_for_event(c);
        if (ev) {
            if (ev->response_type == 0) {
                xcb_generic_error_t *err = (xcb_generic_error_t *)ev;
                printf("Unexpected X Error %d\n", err->error_code);
                printf("   Sequence %d\n", err->sequence);
                printf("   Resource ID 0x%X\n", err->resource_id);
                printf("   Opcode: %d.%d\n", err->major_code, err->minor_code);
                return 1;
            }
            printf("Unexpected X Event %d\n", ev->response_type);
            return 1;
        }

        uint32_t siz = ranval(&ran) % MAX_PROP_LEN + 1;
        xcb_change_property(c, XCB_PROP_MODE_REPLACE, win, XCB_ATOM_STRING, XCB_ATOM_STRING, 8, siz, buf);
    }

    return 0;
}


#define rot(x,k) (((x)<<(k))|((x)>>(32-(k))))
static uint32_t ranval(ranctx *x) {
    uint32_t e = x->a - rot(x->b, 27);
    x->a = x->b ^ rot(x->c, 17);
    x->b = x->c + x->d;
    x->c = x->d + e;
    x->d = e + x->a;
    return x->d;
}

static void raninit(ranctx *x, uint32_t seed) {
    uint32_t i;
    x->a = 0xf1ea5eed, x->b = x->c = x->d = seed;
    for (i = 0; i<20; ++i) {
        (void)ranval(x);
    }
}

Signed-off-by: Peter Harris <pharris@opentext.com>
2021-06-04 14:31:13 +00:00
doc Fix typos & awkward wording in tutorial 2014-07-11 20:41:15 -07:00
m4 config: issue an error if DRI3 is requested, but sendfds is not available 2014-08-06 13:26:08 +02:00
man Escape \n to display properly in xcb-requests man page 2015-04-29 23:23:05 -07:00
src Fix writev emulation on Windows 2021-06-04 14:31:13 +00:00
tests tests: don't use deprecated fail_unless check API 2020-11-18 23:06:05 -05:00
tools Match only XCB-namespaced XID generators when converting to xcb_generate_id. 2006-10-15 12:34:30 -07:00
.autom4te.cfg Use build-aux as autom4te cache directory 2013-08-15 00:35:07 +02:00
.gitignore gitignore: add files generated by make check 2020-11-18 23:06:32 -05:00
COPYING Fix the year in COPYING. 2006-04-27 17:32:20 -07:00
Makefile.am Add README.md to EXTRA_DIST 2019-02-17 12:23:17 -08:00
NEWS Release libxcb 1.14 2020-02-22 12:20:08 -08:00
README.md Update README for gitlab migration 2019-02-16 13:41:28 -08:00
autogen.sh autogen.sh: Implement GNOME Build API 2013-01-16 13:20:49 -05:00
check-pc-requires Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
configure.ac tests: don't use deprecated fail_unless check API 2020-11-18 23:06:05 -05:00
xcb-composite.pc.in Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
xcb-damage.pc.in Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
xcb-dpms.pc.in Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
xcb-dri2.pc.in Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
xcb-dri3.pc.in Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
xcb-ge.pc.in optionally build the GE extension 2017-03-11 10:51:33 +01:00
xcb-glx.pc.in Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
xcb-present.pc.in Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
xcb-randr.pc.in Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
xcb-record.pc.in Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
xcb-render.pc.in Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
xcb-res.pc.in Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
xcb-screensaver.pc.in Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
xcb-shape.pc.in Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
xcb-shm.pc.in Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
xcb-sync.pc.in Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
xcb-xevie.pc.in Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
xcb-xf86dri.pc.in Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
xcb-xfixes.pc.in Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
xcb-xinerama.pc.in Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
xcb-xinput.pc.in Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
xcb-xkb.pc.in Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
xcb-xprint.pc.in Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
xcb-xselinux.pc.in Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
xcb-xtest.pc.in Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
xcb-xv.pc.in Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
xcb-xvmc.pc.in Move internal/private dependencies to Requires.private 2014-10-03 23:53:54 +02:00
xcb.pc.in Store xcbproto version libxcb was compiled with 2009-05-25 12:20:23 +02:00

About libxcb

libxcb provides an interface to the X Window System protocol, which replaces the traditional Xlib interface. It has several advantages over Xlib, including:

  • size: small, simple library, and lower memory footprint
  • latency hiding: batch several requests and wait for the replies later
  • direct protocol access: interface and protocol correspond exactly
  • proven thread support: transparently access XCB from multiple threads
  • easy extension implementation: interfaces auto-generated from XML-XCB

Xlib also uses XCB as a transport layer, allowing software to make requests and receive responses with both, which eases porting to XCB. However, client programs, libraries, and toolkits will gain the most benefit from a native XCB port.

More information about xcb is available from our website:

https://xcb.freedesktop.org/

Please report any issues you find to the freedesktop.org bug tracker at:

https://gitlab.freedesktop.org/xorg/lib/libxcb/issues

Discussion about XCB occurs on the XCB mailing list:

https://lists.freedesktop.org/mailman/listinfo/xcb

You can obtain the latest development versions of XCB using GIT from the libxcb code repository at:

https://gitlab.freedesktop.org/xorg/lib/libxcb

For anonymous checkouts, use:

git clone https://gitlab.freedesktop.org/xorg/lib/libxcb.git

For developers, use:

git clone git@gitlab.freedesktop.org:xorg/lib/libxcb.git