X-Git-Url: http://git.demorecorder.com/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fxcb_in.c;h=0c68208dd0510636f7a311008536dad41f3cbb61;hb=96e55444b9b9500420f9132a1ace720100a26398;hp=1cb6b69de7db2f7d74200a2f48fd97b945e9d600;hpb=e0fac22caaf27b3e461807f8c563d0457938baa6;p=free-sw%2Fxcb%2Flibxcb diff --git a/src/xcb_in.c b/src/xcb_in.c index 1cb6b69..0c68208 100644 --- a/src/xcb_in.c +++ b/src/xcb_in.c @@ -39,6 +39,7 @@ #define XCB_ERROR 0 #define XCB_REPLY 1 +#define XCB_XGE_EVENT 35 struct event_list { xcb_generic_event_t *event; @@ -51,7 +52,8 @@ struct reply_list { }; typedef struct pending_reply { - unsigned int request; + unsigned int first_request; + unsigned int last_request; enum workarounds workaround; int flags; struct pending_reply *next; @@ -77,6 +79,7 @@ static int read_packet(xcb_connection_t *c) { xcb_generic_reply_t genrep; int length = 32; + int eventlength = 0; /* length after first 32 bytes for GenericEvents */ void *buf; pending_reply *pend = 0; struct event_list *event; @@ -110,7 +113,7 @@ static int read_packet(xcb_connection_t *c) } while(c->in.pending_replies && - XCB_SEQUENCE_COMPARE (c->in.pending_replies->request, <=, c->in.request_completed)) + XCB_SEQUENCE_COMPARE (c->in.pending_replies->last_request, <=, c->in.request_completed)) { pending_reply *oldpend = c->in.pending_replies; c->in.pending_replies = oldpend->next; @@ -126,7 +129,9 @@ static int read_packet(xcb_connection_t *c) if(genrep.response_type == XCB_ERROR || genrep.response_type == XCB_REPLY) { pend = c->in.pending_replies; - if(pend && pend->request != c->in.request_read) + if(pend && + (XCB_SEQUENCE_COMPARE(c->in.request_read, <, pend->first_request) || + XCB_SEQUENCE_COMPARE(c->in.request_read, >, pend->last_request))) pend = 0; } @@ -141,17 +146,36 @@ static int read_packet(xcb_connection_t *c) length += genrep.length * 4; } - buf = malloc(length + (genrep.response_type == XCB_REPLY ? 0 : sizeof(uint32_t))); + /* XGE events may have sizes > 32 */ + if (genrep.response_type == XCB_XGE_EVENT) + { + eventlength = ((xcb_ge_event_t*)&genrep)->length * 4; + } + + buf = malloc(length + eventlength + + (genrep.response_type == XCB_REPLY ? 0 : sizeof(uint32_t))); if(!buf) { _xcb_conn_shutdown(c); return 0; } + if(_xcb_in_read_block(c, buf, length) <= 0) { free(buf); return 0; } + + /* pull in XGE event data if available, append after event struct */ + if (eventlength) + { + if(_xcb_in_read_block(c, &((xcb_generic_event_t*)buf)[1], eventlength) <= 0) + { + free(buf); + return 0; + } + } + if(pend && (pend->flags & XCB_REQUEST_DISCARD_REPLY)) { free(buf); @@ -170,6 +194,7 @@ static int read_packet(xcb_connection_t *c) if(!cur) { _xcb_conn_shutdown(c); + free(buf); return 0; } cur->reply = buf; @@ -231,7 +256,7 @@ static void free_reply_list(struct reply_list *head) } } -static int read_block(const int fd, void *buf, const size_t len) +static int read_block(const int fd, void *buf, const ssize_t len) { int done = 0; while(done < len) @@ -319,7 +344,7 @@ void *xcb_wait_for_reply(xcb_connection_t *c, unsigned int request, xcb_generic_ if(c->has_error) return 0; - _xcb_lock_io(c); + pthread_mutex_lock(&c->iolock); /* If this request has not been written yet, write it. */ if(_xcb_out_flush_to(c, request)) @@ -359,7 +384,7 @@ void *xcb_wait_for_reply(xcb_connection_t *c, unsigned int request, xcb_generic_ } wake_up_next_reader(c); - _xcb_unlock_io(c); + pthread_mutex_unlock(&c->iolock); return ret; } @@ -374,9 +399,9 @@ int xcb_poll_for_reply(xcb_connection_t *c, unsigned int request, void **reply, return 1; /* would not block */ } assert(reply != 0); - _xcb_lock_io(c); + pthread_mutex_lock(&c->iolock); ret = poll_for_reply(c, request, reply, error); - _xcb_unlock_io(c); + pthread_mutex_unlock(&c->iolock); return ret; } @@ -385,14 +410,14 @@ xcb_generic_event_t *xcb_wait_for_event(xcb_connection_t *c) xcb_generic_event_t *ret; if(c->has_error) return 0; - _xcb_lock_io(c); + pthread_mutex_lock(&c->iolock); /* get_event returns 0 on empty list. */ while(!(ret = get_event(c))) if(!_xcb_conn_wait(c, &c->in.event_cond, 0, 0)) break; wake_up_next_reader(c); - _xcb_unlock_io(c); + pthread_mutex_unlock(&c->iolock); return ret; } @@ -401,11 +426,12 @@ xcb_generic_event_t *xcb_poll_for_event(xcb_connection_t *c) xcb_generic_event_t *ret = 0; if(!c->has_error) { - _xcb_lock_io(c); + pthread_mutex_lock(&c->iolock); /* FIXME: follow X meets Z architecture changes. */ - if(_xcb_in_read(c)) /* _xcb_in_read shuts down the connection on error */ + ret = get_event(c); + if(!ret && _xcb_in_read(c)) /* _xcb_in_read shuts down the connection on error */ ret = get_event(c); - _xcb_unlock_io(c); + pthread_mutex_unlock(&c->iolock); } return ret; } @@ -483,7 +509,7 @@ int _xcb_in_expect_reply(xcb_connection_t *c, unsigned int request, enum workaro _xcb_conn_shutdown(c); return 0; } - pend->request = request; + pend->first_request = pend->last_request = request; pend->workaround = workaround; pend->flags = flags; pend->next = 0;