X-Git-Url: http://git.demorecorder.com/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fxcb_out.c;h=a3cb2e4ef58fb332a06973a974598ab3e64a5030;hb=1b83f8f8f326eca9d8852c82dd36696f81a720dc;hp=a215bccbf06a074f8db2a1727852e13aa0338783;hpb=5b7182c659391160239467f1041a1d755db45bd3;p=free-sw%2Fxcb%2Flibxcb diff --git a/src/xcb_out.c b/src/xcb_out.c index a215bcc..a3cb2e4 100644 --- a/src/xcb_out.c +++ b/src/xcb_out.c @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -47,6 +48,40 @@ static int force_sequence_wrap(XCBConnection *c) return ret; } +static int _xcb_write(const int fd, char (*buf)[], int *count) +{ + int n = write(fd, *buf, *count); + if(n > 0) + { + *count -= n; + if(*count) + memmove(*buf, *buf + n, *count); + } + return n; +} + +static int _xcb_writev(const int fd, struct iovec *vec, int count) +{ + int n = writev(fd, vec, count); + if(n > 0) + { + int rem = n; + for(; count; --count, ++vec) + { + int cur = vec->iov_len; + if(cur > rem) + cur = rem; + vec->iov_len -= cur; + vec->iov_base = (char *) vec->iov_base + cur; + rem -= cur; + if(vec->iov_len) + break; + } + assert(rem == 0); + } + return n; +} + /* Public interface */ CARD32 XCBGetMaximumRequestLength(XCBConnection *c) @@ -174,7 +209,6 @@ int _xcb_out_init(_xcb_out *out) out->vec = 0; out->vec_len = 0; - out->last_request = 0; out->request = 0; out->request_written = 0; @@ -200,8 +234,9 @@ int _xcb_out_write(XCBConnection *c) else n = _xcb_write(c->fd, &c->out.queue, &c->out.queue_len); - if(n < 0 && errno == EAGAIN) - n = 1; + /* XXX: should "nothing was written" be considered failure or + * success for this function? it's not an I/O error, but... */ + n = (n > 0) || (n < 0 && errno == EAGAIN); if(c->out.vec_len) { @@ -259,7 +294,7 @@ int _xcb_out_write_block(XCBConnection *c, struct iovec *vector, size_t count) c->out.vec[c->out.vec_len].iov_base = (void *) pad; c->out.vec[c->out.vec_len++].iov_len = XCB_PAD(vector[i].iov_len); } - if(_xcb_out_flush(c) <= 0) + if(!_xcb_out_flush(c)) len = -1; free(c->out.vec); c->out.vec = 0; @@ -270,10 +305,9 @@ int _xcb_out_write_block(XCBConnection *c, struct iovec *vector, size_t count) int _xcb_out_flush(XCBConnection *c) { int ret = 1; - while(ret > 0 && (c->out.queue_len || c->out.vec_len)) - ret = _xcb_conn_wait(c, /*should_write*/ 1, &c->out.cond); - c->out.last_request = 0; c->out.request_written = c->out.request; + while(ret && (c->out.queue_len || c->out.vec_len)) + ret = _xcb_conn_wait(c, /*should_write*/ 1, &c->out.cond); pthread_cond_broadcast(&c->out.cond); return ret; }