X-Git-Url: http://git.demorecorder.com/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fxcb_in.c;h=f61377274f49fce15e7e54d1bfb6eef7919ae253;hb=db332dcda989b5b021dc220c102666f695c772cf;hp=690f623c227a5ba7c9f90575b62284b8ca0d066a;hpb=a3bd6f4760b5b3f5f360a690920839646e2b9d06;p=free-sw%2Fxcb%2Flibxcb diff --git a/src/xcb_in.c b/src/xcb_in.c index 690f623..f613772 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; @@ -77,6 +78,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; @@ -108,8 +110,6 @@ static int read_packet(xcb_connection_t *c) } c->in.request_completed = c->in.request_read - 1; } - if(genrep.response_type == XCB_ERROR) - c->in.request_completed = c->in.request_read; while(c->in.pending_replies && XCB_SEQUENCE_COMPARE (c->in.pending_replies->request, <=, c->in.request_completed)) @@ -120,6 +120,9 @@ static int read_packet(xcb_connection_t *c) c->in.pending_replies_tail = &c->in.pending_replies; free(oldpend); } + + if(genrep.response_type == XCB_ERROR) + c->in.request_completed = c->in.request_read; } if(genrep.response_type == XCB_ERROR || genrep.response_type == XCB_REPLY) @@ -140,17 +143,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); @@ -169,6 +191,7 @@ static int read_packet(xcb_connection_t *c) if(!cur) { _xcb_conn_shutdown(c); + free(buf); return 0; } cur->reply = buf; @@ -230,7 +253,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) @@ -318,7 +341,7 @@ void *xcb_wait_for_reply(xcb_connection_t *c, unsigned int request, xcb_generic_ if(c->has_error) return 0; - pthread_mutex_lock(&c->iolock); + _xcb_lock_io(c); /* If this request has not been written yet, write it. */ if(_xcb_out_flush_to(c, request)) @@ -358,7 +381,7 @@ void *xcb_wait_for_reply(xcb_connection_t *c, unsigned int request, xcb_generic_ } wake_up_next_reader(c); - pthread_mutex_unlock(&c->iolock); + _xcb_unlock_io(c); return ret; } @@ -373,9 +396,9 @@ int xcb_poll_for_reply(xcb_connection_t *c, unsigned int request, void **reply, return 1; /* would not block */ } assert(reply != 0); - pthread_mutex_lock(&c->iolock); + _xcb_lock_io(c); ret = poll_for_reply(c, request, reply, error); - pthread_mutex_unlock(&c->iolock); + _xcb_unlock_io(c); return ret; } @@ -384,51 +407,37 @@ xcb_generic_event_t *xcb_wait_for_event(xcb_connection_t *c) xcb_generic_event_t *ret; if(c->has_error) return 0; - pthread_mutex_lock(&c->iolock); + _xcb_lock_io(c); /* 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); - pthread_mutex_unlock(&c->iolock); + _xcb_unlock_io(c); return ret; } -xcb_generic_event_t *xcb_poll_for_event(xcb_connection_t *c, int *error) +xcb_generic_event_t *xcb_poll_for_event(xcb_connection_t *c) { + xcb_generic_event_t *ret = 0; if(!c->has_error) { - xcb_generic_event_t *ret = 0; - int success; - pthread_mutex_lock(&c->iolock); + _xcb_lock_io(c); /* FIXME: follow X meets Z architecture changes. */ - success = _xcb_in_read(c); - if(success) + ret = get_event(c); + if(!ret && _xcb_in_read(c)) /* _xcb_in_read shuts down the connection on error */ ret = get_event(c); - pthread_mutex_unlock(&c->iolock); - if(success) - { - if(error) - *error = 0; - return ret; - } + _xcb_unlock_io(c); } - if(error) - *error = -1; - else - { - fprintf(stderr, "xcb_poll_for_event_t: I/O error occured, but no handler provided.\n"); - abort(); - } - return 0; + return ret; } xcb_generic_error_t *xcb_request_check(xcb_connection_t *c, xcb_void_cookie_t cookie) { /* FIXME: this could hold the lock to avoid syncing unnecessarily, but - * that would require factoring the locking out of xcb_get_input_focus_t, - * xcb_get_input_focus_reply_t, and xcb_wait_for_reply_t. */ + * that would require factoring the locking out of xcb_get_input_focus, + * xcb_get_input_focus_reply, and xcb_wait_for_reply. */ xcb_generic_error_t *ret; void *reply; if(c->has_error)