X-Git-Url: http://git.demorecorder.com/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fxcb_in.c;h=8a7af920b30f26f748fbc468882ff3be2c04227c;hb=1b33867fa996034deb50819ae54640be501f8d20;hp=1199e2376b5f160b869a997d7bab7eaae640f794;hpb=29a974f212aae9eeff4fde99f110cee08f0312f3;p=free-sw%2Fxcb%2Flibxcb diff --git a/src/xcb_in.c b/src/xcb_in.c index 1199e23..8a7af92 100644 --- a/src/xcb_in.c +++ b/src/xcb_in.c @@ -25,6 +25,10 @@ /* Stuff that reads stuff from the server. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include @@ -51,11 +55,6 @@ #define XCB_REPLY 1 #define XCB_XGE_EVENT 35 -/* required for compiling for Win32 using MinGW */ -#ifndef MSG_WAITALL -#define MSG_WAITALL 0 -#endif - struct event_list { xcb_generic_event_t *event; struct event_list *next; @@ -94,8 +93,9 @@ static void remove_finished_readers(reader_list **prev_reader, uint64_t complete 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 */ + uint64_t length = 32; + uint64_t eventlength = 0; /* length after first 32 bytes for GenericEvents */ + uint64_t bufsize; void *buf; pending_reply *pend = 0; struct event_list *event; @@ -167,14 +167,18 @@ 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 + - (genrep.response_type == XCB_REPLY ? 0 : sizeof(uint32_t))); + bufsize = length + eventlength + + (genrep.response_type == XCB_REPLY ? 0 : sizeof(uint32_t)); + if (bufsize < INT32_MAX) + buf = malloc((size_t) bufsize); + else + buf = NULL; if(!buf) { - _xcb_conn_shutdown(c); + _xcb_conn_shutdown(c, XCB_CONN_CLOSED_MEM_INSUFFICIENT); return 0; } @@ -210,7 +214,7 @@ static int read_packet(xcb_connection_t *c) struct reply_list *cur = malloc(sizeof(struct reply_list)); if(!cur) { - _xcb_conn_shutdown(c); + _xcb_conn_shutdown(c, XCB_CONN_CLOSED_MEM_INSUFFICIENT); free(buf); return 0; } @@ -227,7 +231,7 @@ static int read_packet(xcb_connection_t *c) event = malloc(sizeof(struct event_list)); if(!event) { - _xcb_conn_shutdown(c); + _xcb_conn_shutdown(c, XCB_CONN_CLOSED_MEM_INSUFFICIENT); free(buf); return 0; } @@ -269,7 +273,7 @@ static int read_block(const int fd, void *buf, const ssize_t len) int done = 0; while(done < len) { - int ret = recv(fd, ((char *) buf) + done, len - done,MSG_WAITALL); + int ret = recv(fd, ((char *) buf) + done, len - done, 0); if(ret > 0) done += ret; #ifndef _WIN32 @@ -433,7 +437,7 @@ static void insert_pending_discard(xcb_connection_t *c, pending_reply **prev_nex pend = malloc(sizeof(*pend)); if(!pend) { - _xcb_conn_shutdown(c); + _xcb_conn_shutdown(c, XCB_CONN_CLOSED_MEM_INSUFFICIENT); return; } @@ -527,7 +531,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) @@ -535,13 +539,23 @@ 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 && c->in.reading == 0 && _xcb_in_read(c)) /* _xcb_in_read shuts down the connection on error */ ret = get_event(c); pthread_mutex_unlock(&c->iolock); } return ret; } +xcb_generic_event_t *xcb_poll_for_event(xcb_connection_t *c) +{ + return poll_for_next_event(c, 0); +} + +xcb_generic_event_t *xcb_poll_for_queued_event(xcb_connection_t *c) +{ + return poll_for_next_event(c, 1); +} + xcb_generic_error_t *xcb_request_check(xcb_connection_t *c, xcb_void_cookie_t cookie) { uint64_t request; @@ -623,7 +637,7 @@ int _xcb_in_expect_reply(xcb_connection_t *c, uint64_t request, enum workarounds assert(workaround != WORKAROUND_NONE || flags != 0); if(!pend) { - _xcb_conn_shutdown(c); + _xcb_conn_shutdown(c, XCB_CONN_CLOSED_MEM_INSUFFICIENT); return 0; } pend->first_request = pend->last_request = request; @@ -651,7 +665,7 @@ void _xcb_in_replies_done(xcb_connection_t *c) int _xcb_in_read(xcb_connection_t *c) { - int n = recv(c->fd, c->in.queue + c->in.queue_len, sizeof(c->in.queue) - c->in.queue_len,MSG_WAITALL); + int n = recv(c->fd, c->in.queue + c->in.queue_len, sizeof(c->in.queue) - c->in.queue_len, 0); if(n > 0) c->in.queue_len += n; while(read_packet(c)) @@ -662,7 +676,7 @@ int _xcb_in_read(xcb_connection_t *c) if((n > 0) || (n < 0 && WSAGetLastError() == WSAEWOULDBLOCK)) #endif /* !_WIN32 */ return 1; - _xcb_conn_shutdown(c); + _xcb_conn_shutdown(c, XCB_CONN_ERROR); return 0; } @@ -681,7 +695,7 @@ int _xcb_in_read_block(xcb_connection_t *c, void *buf, int len) int ret = read_block(c->fd, (char *) buf + done, len - done); if(ret <= 0) { - _xcb_conn_shutdown(c); + _xcb_conn_shutdown(c, XCB_CONN_ERROR); return ret; } }