X-Git-Url: http://git.demorecorder.com/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fxcb_in.c;h=6f084ba9373261b0393d9caac14688690662f45e;hb=a1eff0c49a2dbb328a79edbeb2b851fa1dfe9e61;hp=967beac04dbda1d47363297006ff11b641e19a0b;hpb=6149c7a6b57a193bc132fbc35b1772b75e5c7ca7;p=free-sw%2Fxcb%2Flibxcb diff --git a/src/xcb_in.c b/src/xcb_in.c index 967beac..6f084ba 100644 --- a/src/xcb_in.c +++ b/src/xcb_in.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -152,6 +153,27 @@ static int read_packet(XCBConnection *c) return 1; /* I have something for you... */ } +static int read_block(const int fd, void *buf, const size_t len) +{ + int done = 0; + while(done < len) + { + int ret = read(fd, ((char *) buf) + done, len - done); + if(ret > 0) + done += ret; + if(ret < 0 && errno == EAGAIN) + { + fd_set fds; + FD_ZERO(&fds); + FD_SET(fd, &fds); + ret = select(fd + 1, &fds, 0, 0, 0); + } + if(ret <= 0) + return ret; + } + return len; +} + /* Public interface */ void *XCBWaitForReply(XCBConnection *c, unsigned int request, XCBGenericError **e) @@ -221,11 +243,6 @@ XCBGenericEvent *XCBWaitEvent(XCBConnection *c) XCBGenericEvent *XCBWaitForEvent(XCBConnection *c) { XCBGenericEvent *ret; - -#if XCBTRACEEVENT - fprintf(stderr, "Entering XCBWaitEvent\n"); -#endif - pthread_mutex_lock(&c->iolock); /* _xcb_list_remove_head returns 0 on empty list. */ while(!(ret = _xcb_queue_dequeue(c->in.events))) @@ -234,11 +251,6 @@ XCBGenericEvent *XCBWaitForEvent(XCBConnection *c) wake_up_next_reader(c); pthread_mutex_unlock(&c->iolock); - -#if XCBTRACEEVENT - fprintf(stderr, "Leaving XCBWaitEvent, event type %d\n", ret ? ret->response_type : -1); -#endif - return ret; } @@ -327,7 +339,9 @@ int _xcb_in_expect_reply(XCBConnection *c, unsigned int request, enum workaround int _xcb_in_read(XCBConnection *c) { - int n = _xcb_readn(c->fd, c->in.queue, sizeof(c->in.queue), &c->in.queue_len); + int n = read(c->fd, c->in.queue + c->in.queue_len, sizeof(c->in.queue) - c->in.queue_len); + if(n > 0) + c->in.queue_len += n; while(read_packet(c)) /* empty */; return (n > 0) || (n < 0 && errno == EAGAIN); @@ -345,7 +359,7 @@ int _xcb_in_read_block(XCBConnection *c, void *buf, int len) if(len > done) { - int ret = _xcb_read_block(c->fd, (char *) buf + done, len - done); + int ret = read_block(c->fd, (char *) buf + done, len - done); if(ret <= 0) return ret; }