X-Git-Url: http://git.demorecorder.com/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fxcb_conn.c;h=2da3150e8f194255b0d0d1e578d3a7798164307a;hb=b83f18a4cc2303dfda59807d56e16bbc5c18b09d;hp=792dfb85cb5c6ea341ea2ae865c53ed1b772cb14;hpb=83e652f566671f96ffc53a3c0099a84a1606c695;p=free-sw%2Fxcb%2Flibxcb diff --git a/src/xcb_conn.c b/src/xcb_conn.c index 792dfb8..2da3150 100644 --- a/src/xcb_conn.c +++ b/src/xcb_conn.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "xcb.h" #include "xcbint.h" @@ -89,8 +90,10 @@ static int write_setup(XCBConnection *c, XCBAuthInfo *auth_info) assert(count <= sizeof(parts) / sizeof(*parts)); pthread_mutex_lock(&c->iolock); - _xcb_out_write_block(c, parts, count); - ret = _xcb_out_flush(c); + { + struct iovec *parts_ptr = parts; + ret = _xcb_out_send(c, &parts_ptr, &count); + } pthread_mutex_unlock(&c->iolock); return ret; } @@ -136,6 +139,34 @@ static int read_setup(XCBConnection *c) return 1; } +/* precondition: there must be something for us to write. */ +static int write_vec(XCBConnection *c, struct iovec **vector, int *count) +{ + int n; + assert(!c->out.queue_len); + n = writev(c->fd, *vector, *count); + if(n < 0 && errno == EAGAIN) + return 1; + if(n <= 0) + return 0; + + for(; *count; --*count, ++*vector) + { + int cur = (*vector)->iov_len; + if(cur > n) + cur = n; + (*vector)->iov_len -= cur; + (*vector)->iov_base = (char *) (*vector)->iov_base + cur; + n -= cur; + if((*vector)->iov_len) + break; + } + if(!*count) + *vector = 0; + assert(n == 0); + return 1; +} + /* Public interface */ XCBConnSetupSuccessRep *XCBGetSetup(XCBConnection *c) @@ -231,7 +262,7 @@ int _xcb_conn_wait(XCBConnection *c, pthread_cond_t *cond, struct iovec **vector ret = ret && _xcb_in_read(c); if(FD_ISSET(c->fd, &wfds)) - ret = ret && _xcb_out_write(c, vector, count); + ret = ret && write_vec(c, vector, count); } if(count)