#include <assert.h>
#include <stdlib.h>
+#include <unistd.h>
#include <string.h>
#include <errno.h>
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)
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)
{