aboutsummaryrefslogtreecommitdiff
path: root/libxcb
diff options
context:
space:
mode:
Diffstat (limited to 'libxcb')
-rw-r--r--libxcb/src/xcb.h43
-rw-r--r--libxcb/src/xcb_in.c49
-rw-r--r--libxcb/src/xcb_util.c24
-rw-r--r--libxcb/src/xcbint.h2
4 files changed, 33 insertions, 85 deletions
diff --git a/libxcb/src/xcb.h b/libxcb/src/xcb.h
index b1bab44da..cfe311ecf 100644
--- a/libxcb/src/xcb.h
+++ b/libxcb/src/xcb.h
@@ -272,39 +272,20 @@ xcb_generic_event_t *xcb_wait_for_event(xcb_connection_t *c);
xcb_generic_event_t *xcb_poll_for_event(xcb_connection_t *c);
/**
- * @brief Returns the next event or error that precedes the given request.
+ * @brief Returns the next event without reading from the connection.
* @param c: The connection to the X server.
- * @param request: The limiting sequence number.
- * @return The next event from the server.
+ * @return The next already queued event from the server.
+ *
+ * This is a version of xcb_poll_for_event that only examines the
+ * event queue for new events. The function doesn't try to read new
+ * events from the connection if no queued events are found.
*
- * Returns the next event or error with a sequence number less than or
- * equal to the given sequence number, or returns NULL if no such event can
- * ever arrive. Blocks until either a suitable event or error arrive, or a
- * response arrives that proves no such event is coming, or an I/O error
- * occurs.
- *
- * After processing a request, the X server sends responses in a specific
- * order. First come any events that the request generated, then any
- * replies for the request, then the error response if there is one. After
- * that, the server may spontaneously send more events with the same
- * sequence number, which are not related to that request.
- *
- * This function will always return events from the pre-reply phase of the
- * specified request. It may also return events from the unrelated
- * post-reply stream, as long as they have the same sequence number.
- *
- * This function is useful for callers that need to process responses in
- * wire-order.
- *
- * Implementation note: You cannot currently use this function to ensure
- * that you process responses in exactly wire-order, because depending on
- * the sequence of calls you make and the timing of server responses,
- * post-reply events with the same sequence number may be returned as part
- * of the pre-reply event stream, even though they were separated by a
- * reply or error. In practice this kind of error is unlikely to matter,
- * but it may be fixed in the future.
- */
-xcb_generic_event_t *xcb_wait_for_event_until(xcb_connection_t *c, unsigned int request);
+ * This function is useful for callers that know in advance that all
+ * interesting events have already been read from the connection. For
+ * example, callers might use xcb_wait_for_reply and be interested
+ * only of events that preceded a specific reply.
+ */
+xcb_generic_event_t *xcb_poll_for_queued_event(xcb_connection_t *c);
/**
* @brief Return the error for a request, or NULL if none can ever arrive.
diff --git a/libxcb/src/xcb_in.c b/libxcb/src/xcb_in.c
index 0a957a4b2..e0e7a7cac 100644
--- a/libxcb/src/xcb_in.c
+++ b/libxcb/src/xcb_in.c
@@ -63,7 +63,6 @@
#endif
struct event_list {
- uint64_t sequence;
xcb_generic_event_t *event;
struct event_list *next;
};
@@ -132,7 +131,7 @@ static int read_packet(xcb_connection_t *c)
c->in.current_reply = 0;
c->in.current_reply_tail = &c->in.current_reply;
}
- c->in.request_completed = c->in.event_responses_completed = c->in.request_read - 1;
+ c->in.request_completed = c->in.request_read - 1;
}
while(c->in.pending_replies &&
@@ -147,12 +146,9 @@ static int read_packet(xcb_connection_t *c)
}
if(genrep.response_type == XCB_ERROR)
- c->in.request_completed = c->in.event_responses_completed = c->in.request_read;
- else if(genrep.response_type == XCB_REPLY)
- c->in.event_responses_completed = c->in.request_read;
+ c->in.request_completed = c->in.request_read;
remove_finished_readers(&c->in.readers, c->in.request_completed);
- remove_finished_readers(&c->in.event_readers, c->in.event_responses_completed);
}
if(genrep.response_type == XCB_ERROR || genrep.response_type == XCB_REPLY)
@@ -177,7 +173,7 @@ static int read_packet(xcb_connection_t *c)
}
/* XGE events may have sizes > 32 */
- if (genrep.response_type == XCB_XGE_EVENT)
+ if ((genrep.response_type & 0x7f) == XCB_XGE_EVENT)
eventlength = genrep.length * 4;
buf = malloc(length + eventlength +
@@ -241,15 +237,11 @@ static int read_packet(xcb_connection_t *c)
free(buf);
return 0;
}
- event->sequence = c->in.request_read;
event->event = buf;
event->next = 0;
*c->in.events_tail = event;
c->in.events_tail = &event->next;
- if(c->in.event_readers)
- pthread_cond_signal(c->in.event_readers->data);
- else
- pthread_cond_signal(&c->in.event_cond);
+ pthread_cond_signal(&c->in.event_cond);
return 1; /* I have something for you... */
}
@@ -541,7 +533,7 @@ xcb_generic_event_t *xcb_wait_for_event(xcb_connection_t *c)
return ret;
}
-xcb_generic_event_t *xcb_poll_for_event(xcb_connection_t *c)
+static xcb_generic_event_t *poll_for_next_event(xcb_connection_t *c, int queued)
{
xcb_generic_event_t *ret = 0;
if(!c->has_error)
@@ -549,40 +541,21 @@ xcb_generic_event_t *xcb_poll_for_event(xcb_connection_t *c)
pthread_mutex_lock(&c->iolock);
/* FIXME: follow X meets Z architecture changes. */
ret = get_event(c);
- if(!ret && _xcb_in_read(c)) /* _xcb_in_read shuts down the connection on error */
+ if(!ret && !queued && _xcb_in_read(c)) /* _xcb_in_read shuts down the connection on error */
ret = get_event(c);
pthread_mutex_unlock(&c->iolock);
}
return ret;
}
-static xcb_generic_event_t *get_event_until(xcb_connection_t *c, uint64_t request)
+xcb_generic_event_t *xcb_poll_for_event(xcb_connection_t *c)
{
- if(c->in.events && XCB_SEQUENCE_COMPARE(c->in.events->sequence, <=, request))
- return get_event(c);
- return 0;
+ return poll_for_next_event(c, 0);
}
-xcb_generic_event_t *xcb_wait_for_event_until(xcb_connection_t *c, unsigned int request)
+xcb_generic_event_t *xcb_poll_for_queued_event(xcb_connection_t *c)
{
- pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
- reader_list reader;
- xcb_generic_event_t *ret;
- if(c->has_error)
- return 0;
- pthread_mutex_lock(&c->iolock);
-
- insert_reader(&c->in.event_readers, &reader, widen(c, request), &cond);
-
- while(!(ret = get_event_until(c, reader.request)) && XCB_SEQUENCE_COMPARE(c->in.event_responses_completed, <, reader.request))
- if(!_xcb_conn_wait(c, &cond, 0, 0))
- break;
-
- remove_reader(&c->in.event_readers, &reader);
- pthread_cond_destroy(&cond);
- _xcb_in_wake_up_next_reader(c);
- pthread_mutex_unlock(&c->iolock);
- return ret;
+ return poll_for_next_event(c, 1);
}
xcb_generic_error_t *xcb_request_check(xcb_connection_t *c, xcb_void_cookie_t cookie)
@@ -655,8 +628,6 @@ void _xcb_in_wake_up_next_reader(xcb_connection_t *c)
int pthreadret;
if(c->in.readers)
pthreadret = pthread_cond_signal(c->in.readers->data);
- else if(c->in.event_readers)
- pthreadret = pthread_cond_signal(c->in.event_readers->data);
else
pthreadret = pthread_cond_signal(&c->in.event_cond);
assert(pthreadret == 0);
diff --git a/libxcb/src/xcb_util.c b/libxcb/src/xcb_util.c
index e1e48ce0d..b999ea528 100644
--- a/libxcb/src/xcb_util.c
+++ b/libxcb/src/xcb_util.c
@@ -178,22 +178,20 @@ static int _xcb_open(const char *host, char *protocol, const int display)
int actual_filelen;
#ifdef HAVE_LAUNCHD
- if(strncmp(host, "/tmp/launch", 11) == 0) {
- base = host;
- host = "";
- protocol = NULL;
- }
+ if(strncmp(host, "/tmp/launch", 11) == 0) {
+ base = host;
+ host = "";
+ protocol = NULL;
+ }
#endif
- if(*host || protocol)
+ /* If protocol or host is "unix", fall through to Unix socket code below */
+ if ((!protocol || (strcmp("unix",protocol) != 0)) &&
+ (*host != '\0') && (strcmp("unix",host) != 0))
{
- if (protocol
- || strcmp("unix",host)) { /* follow the old unix: rule */
-
- /* display specifies TCP */
- unsigned short port = X_TCP_PORT + display;
- return _xcb_open_tcp(host, protocol, port);
- }
+ /* display specifies TCP */
+ unsigned short port = X_TCP_PORT + display;
+ return _xcb_open_tcp(host, protocol, port);
}
#ifndef _WIN32
diff --git a/libxcb/src/xcbint.h b/libxcb/src/xcbint.h
index d1f742104..5950823f0 100644
--- a/libxcb/src/xcbint.h
+++ b/libxcb/src/xcbint.h
@@ -121,7 +121,6 @@ typedef struct _xcb_in {
uint64_t request_expected;
uint64_t request_read;
- uint64_t event_responses_completed;
uint64_t request_completed;
struct reply_list *current_reply;
struct reply_list **current_reply_tail;
@@ -130,7 +129,6 @@ typedef struct _xcb_in {
struct event_list *events;
struct event_list **events_tail;
struct reader_list *readers;
- struct reader_list *event_readers;
struct pending_reply *pending_replies;
struct pending_reply **pending_replies_tail;