assert(pthreadret == 0);
}
-static int readn(const int fd, void *buf, const int buflen, int *count)
-{
- int n = read(fd, ((char *) buf) + *count, buflen - *count);
- if(n > 0)
- *count += n;
- return n;
-}
-
static int read_packet(XCBConnection *c)
{
XCBGenericRep genrep;
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)
int _xcb_in_read(XCBConnection *c)
{
- int n = 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);
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;
}