1 /* Copyright (C) 2001-2004 Bart Massey and Jamey Sharp.
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
17 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 * Except as contained in this notice, the names of the authors or their
21 * institutions shall not be used in advertising or otherwise to promote the
22 * sale, use or other dealings in this Software without prior written
23 * authorization from the authors.
26 /* Stuff that reads stuff from the server. */
43 #include <sys/select.h>
44 #include <sys/socket.h>
48 #include "xcb_windefs.h"
57 #define XCB_XGE_EVENT 35
60 xcb_generic_event_t *event;
61 struct event_list *next;
64 struct xcb_special_event {
66 struct xcb_special_event *next;
68 /* Match XGE events for the specific extension and event ID (the
69 * first 32 bit word after evtype)
75 struct event_list *events;
76 struct event_list **events_tail;
78 pthread_cond_t special_event_cond;
83 struct reply_list *next;
86 typedef struct pending_reply {
87 uint64_t first_request;
88 uint64_t last_request;
89 enum workarounds workaround;
91 struct pending_reply *next;
94 typedef struct reader_list {
97 struct reader_list *next;
100 static void remove_finished_readers(reader_list **prev_reader, uint64_t completed)
102 while(*prev_reader && XCB_SEQUENCE_COMPARE((*prev_reader)->request, <=, completed))
104 /* If you don't have what you're looking for now, you never
105 * will. Wake up and leave me alone. */
106 pthread_cond_signal((*prev_reader)->data);
107 *prev_reader = (*prev_reader)->next;
112 static int read_fds(xcb_connection_t *c, int *fds, int nfd)
114 int *ifds = &c->in.in_fd.fd[c->in.in_fd.ifd];
115 int infd = c->in.in_fd.nfd - c->in.in_fd.ifd;
119 memcpy(fds, ifds, nfd * sizeof (int));
120 c->in.in_fd.ifd += nfd;
125 typedef struct xcb_ge_special_event_t {
126 uint8_t response_type; /**< */
127 uint8_t extension; /**< */
128 uint16_t sequence; /**< */
129 uint32_t length; /**< */
130 uint16_t evtype; /**< */
131 uint8_t pad0[2]; /**< */
132 uint32_t eid; /**< */
133 uint8_t pad1[16]; /**< */
134 } xcb_ge_special_event_t;
136 static int event_special(xcb_connection_t *c,
137 struct event_list *event)
139 struct xcb_special_event *special_event;
140 struct xcb_ge_special_event_t *ges = (void *) event->event;
142 /* Special events are always XGE events */
143 if ((ges->response_type & 0x7f) != XCB_XGE_EVENT)
146 for (special_event = c->in.special_events;
148 special_event = special_event->next)
150 if (ges->extension == special_event->extension &&
151 ges->eid == special_event->eid)
153 *special_event->events_tail = event;
154 special_event->events_tail = &event->next;
155 if (special_event->stamp)
156 ++(*special_event->stamp);
157 pthread_cond_signal(&special_event->special_event_cond);
165 static int read_packet(xcb_connection_t *c)
167 xcb_generic_reply_t genrep;
168 uint64_t length = 32;
169 uint64_t eventlength = 0; /* length after first 32 bytes for GenericEvents */
170 int nfd = 0; /* Number of file descriptors attached to the reply */
173 pending_reply *pend = 0;
174 struct event_list *event;
176 /* Wait for there to be enough data for us to read a whole packet */
177 if(c->in.queue_len < length)
180 /* Get the response type, length, and sequence number. */
181 memcpy(&genrep, c->in.queue, sizeof(genrep));
183 /* Compute 32-bit sequence number of this packet. */
184 if((genrep.response_type & 0x7f) != XCB_KEYMAP_NOTIFY)
186 uint64_t lastread = c->in.request_read;
187 c->in.request_read = (lastread & UINT64_C(0xffffffffffff0000)) | genrep.sequence;
188 if(XCB_SEQUENCE_COMPARE(c->in.request_read, <, lastread))
189 c->in.request_read += 0x10000;
190 if(XCB_SEQUENCE_COMPARE(c->in.request_read, >, c->in.request_expected))
191 c->in.request_expected = c->in.request_read;
193 if(c->in.request_read != lastread)
195 if(c->in.current_reply)
197 _xcb_map_put(c->in.replies, lastread, c->in.current_reply);
198 c->in.current_reply = 0;
199 c->in.current_reply_tail = &c->in.current_reply;
201 c->in.request_completed = c->in.request_read - 1;
204 while(c->in.pending_replies &&
205 c->in.pending_replies->workaround != WORKAROUND_EXTERNAL_SOCKET_OWNER &&
206 XCB_SEQUENCE_COMPARE (c->in.pending_replies->last_request, <=, c->in.request_completed))
208 pending_reply *oldpend = c->in.pending_replies;
209 c->in.pending_replies = oldpend->next;
211 c->in.pending_replies_tail = &c->in.pending_replies;
215 if(genrep.response_type == XCB_ERROR)
216 c->in.request_completed = c->in.request_read;
218 remove_finished_readers(&c->in.readers, c->in.request_completed);
221 if(genrep.response_type == XCB_ERROR || genrep.response_type == XCB_REPLY)
223 pend = c->in.pending_replies;
225 !(XCB_SEQUENCE_COMPARE(pend->first_request, <=, c->in.request_read) &&
226 (pend->workaround == WORKAROUND_EXTERNAL_SOCKET_OWNER ||
227 XCB_SEQUENCE_COMPARE(c->in.request_read, <=, pend->last_request))))
231 /* For reply packets, check that the entire packet is available. */
232 if(genrep.response_type == XCB_REPLY)
234 if(pend && pend->workaround == WORKAROUND_GLX_GET_FB_CONFIGS_BUG)
236 uint32_t *p = (uint32_t *) c->in.queue;
237 genrep.length = p[2] * p[3] * 2;
239 length += genrep.length * 4;
241 /* XXX a bit of a hack -- we "know" that all FD replys place
242 * the number of fds in the pad0 byte */
243 if (pend && pend->flags & XCB_REQUEST_REPLY_FDS)
247 /* XGE events may have sizes > 32 */
248 if ((genrep.response_type & 0x7f) == XCB_XGE_EVENT)
249 eventlength = genrep.length * 4;
251 bufsize = length + eventlength + nfd * sizeof(int) +
252 (genrep.response_type == XCB_REPLY ? 0 : sizeof(uint32_t));
253 if (bufsize < INT32_MAX)
254 buf = malloc((size_t) bufsize);
259 _xcb_conn_shutdown(c, XCB_CONN_CLOSED_MEM_INSUFFICIENT);
263 if(_xcb_in_read_block(c, buf, length) <= 0)
269 /* pull in XGE event data if available, append after event struct */
272 if(_xcb_in_read_block(c, &((xcb_generic_event_t*)buf)[1], eventlength) <= 0)
282 if (!read_fds(c, (int *) &((char *) buf)[length], nfd))
290 if(pend && (pend->flags & XCB_REQUEST_DISCARD_REPLY))
296 if(genrep.response_type != XCB_REPLY)
297 ((xcb_generic_event_t *) buf)->full_sequence = c->in.request_read;
299 /* reply, or checked error */
300 if( genrep.response_type == XCB_REPLY ||
301 (genrep.response_type == XCB_ERROR && pend && (pend->flags & XCB_REQUEST_CHECKED)))
303 struct reply_list *cur = malloc(sizeof(struct reply_list));
306 _xcb_conn_shutdown(c, XCB_CONN_CLOSED_MEM_INSUFFICIENT);
312 *c->in.current_reply_tail = cur;
313 c->in.current_reply_tail = &cur->next;
314 if(c->in.readers && c->in.readers->request == c->in.request_read)
315 pthread_cond_signal(c->in.readers->data);
319 /* event, or unchecked error */
320 event = malloc(sizeof(struct event_list));
323 _xcb_conn_shutdown(c, XCB_CONN_CLOSED_MEM_INSUFFICIENT);
330 if (!event_special(c, event)) {
331 *c->in.events_tail = event;
332 c->in.events_tail = &event->next;
333 pthread_cond_signal(&c->in.event_cond);
335 return 1; /* I have something for you... */
338 static xcb_generic_event_t *get_event(xcb_connection_t *c)
340 struct event_list *cur = c->in.events;
341 xcb_generic_event_t *ret;
345 c->in.events = cur->next;
347 c->in.events_tail = &c->in.events;
352 static void free_reply_list(struct reply_list *head)
356 struct reply_list *cur = head;
363 static int read_block(const int fd, void *buf, const ssize_t len)
368 int ret = recv(fd, ((char *) buf) + done, len - done, 0);
372 if(ret < 0 && errno == EAGAIN)
374 if(ret == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
383 ret = poll(&pfd, 1, -1);
384 } while (ret == -1 && errno == EINTR);
390 /* Initializing errno here makes sure that for Win32 this loop will execute only once */
393 ret = select(fd + 1, &fds, 0, 0, 0);
394 } while (ret == -1 && errno == EINTR);
395 #endif /* USE_POLL */
403 static int poll_for_reply(xcb_connection_t *c, uint64_t request, void **reply, xcb_generic_error_t **error)
405 struct reply_list *head;
407 /* If an error occurred when issuing the request, fail immediately. */
410 /* We've read requests past the one we want, so if it has replies we have
411 * them all and they're in the replies map. */
412 else if(XCB_SEQUENCE_COMPARE(request, <, c->in.request_read))
414 head = _xcb_map_remove(c->in.replies, request);
415 if(head && head->next)
416 _xcb_map_put(c->in.replies, request, head->next);
418 /* We're currently processing the responses to the request we want, and we
419 * have a reply ready to return. So just return it without blocking. */
420 else if(request == c->in.request_read && c->in.current_reply)
422 head = c->in.current_reply;
423 c->in.current_reply = head->next;
425 c->in.current_reply_tail = &c->in.current_reply;
427 /* We know this request can't have any more replies, and we've already
428 * established it doesn't have a reply now. Don't bother blocking. */
429 else if(request == c->in.request_completed)
431 /* We may have more replies on the way for this request: block until we're
442 if(((xcb_generic_reply_t *) head->reply)->response_type == XCB_ERROR)
445 *error = head->reply;
450 *reply = head->reply;
458 static void insert_reader(reader_list **prev_reader, reader_list *reader, uint64_t request, pthread_cond_t *cond)
460 while(*prev_reader && XCB_SEQUENCE_COMPARE((*prev_reader)->request, <=, request))
461 prev_reader = &(*prev_reader)->next;
462 reader->request = request;
464 reader->next = *prev_reader;
465 *prev_reader = reader;
468 static void remove_reader(reader_list **prev_reader, reader_list *reader)
470 while(*prev_reader && XCB_SEQUENCE_COMPARE((*prev_reader)->request, <=, reader->request))
471 if(*prev_reader == reader)
473 *prev_reader = (*prev_reader)->next;
478 static void *wait_for_reply(xcb_connection_t *c, uint64_t request, xcb_generic_error_t **e)
482 /* If this request has not been written yet, write it. */
483 if(c->out.return_socket || _xcb_out_flush_to(c, request))
485 pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
488 insert_reader(&c->in.readers, &reader, request, &cond);
490 while(!poll_for_reply(c, request, &ret, e))
491 if(!_xcb_conn_wait(c, &cond, 0, 0))
494 remove_reader(&c->in.readers, &reader);
495 pthread_cond_destroy(&cond);
498 _xcb_in_wake_up_next_reader(c);
502 static uint64_t widen(xcb_connection_t *c, unsigned int request)
504 uint64_t widened_request = (c->out.request & UINT64_C(0xffffffff00000000)) | request;
505 if(widened_request > c->out.request)
506 widened_request -= UINT64_C(1) << 32;
507 return widened_request;
510 /* Public interface */
512 void *xcb_wait_for_reply(xcb_connection_t *c, unsigned int request, xcb_generic_error_t **e)
520 pthread_mutex_lock(&c->iolock);
521 ret = wait_for_reply(c, widen(c, request), e);
522 pthread_mutex_unlock(&c->iolock);
526 int *xcb_get_reply_fds(xcb_connection_t *c, void *reply, size_t reply_size)
528 return (int *) (&((char *) reply)[reply_size]);
531 static void insert_pending_discard(xcb_connection_t *c, pending_reply **prev_next, uint64_t seq)
534 pend = malloc(sizeof(*pend));
537 _xcb_conn_shutdown(c, XCB_CONN_CLOSED_MEM_INSUFFICIENT);
541 pend->first_request = seq;
542 pend->last_request = seq;
543 pend->workaround = 0;
544 pend->flags = XCB_REQUEST_DISCARD_REPLY;
545 pend->next = *prev_next;
549 c->in.pending_replies_tail = &pend->next;
552 static void discard_reply(xcb_connection_t *c, uint64_t request)
555 pending_reply **prev_pend;
557 /* Free any replies or errors that we've already read. Stop if
558 * xcb_wait_for_reply would block or we've run out of replies. */
559 while(poll_for_reply(c, request, &reply, 0) && reply)
562 /* If we've proven there are no more responses coming, we're done. */
563 if(XCB_SEQUENCE_COMPARE(request, <=, c->in.request_completed))
566 /* Walk the list of pending requests. Mark the first match for deletion. */
567 for(prev_pend = &c->in.pending_replies; *prev_pend; prev_pend = &(*prev_pend)->next)
569 if(XCB_SEQUENCE_COMPARE((*prev_pend)->first_request, >, request))
572 if((*prev_pend)->first_request == request)
574 /* Pending reply found. Mark for discard: */
575 (*prev_pend)->flags |= XCB_REQUEST_DISCARD_REPLY;
580 /* Pending reply not found (likely due to _unchecked request). Create one: */
581 insert_pending_discard(c, prev_pend, request);
584 void xcb_discard_reply(xcb_connection_t *c, unsigned int sequence)
589 /* If an error occurred when issuing the request, fail immediately. */
593 pthread_mutex_lock(&c->iolock);
594 discard_reply(c, widen(c, sequence));
595 pthread_mutex_unlock(&c->iolock);
598 int xcb_poll_for_reply(xcb_connection_t *c, unsigned int request, void **reply, xcb_generic_error_t **error)
606 return 1; /* would not block */
609 pthread_mutex_lock(&c->iolock);
610 ret = poll_for_reply(c, widen(c, request), reply, error);
611 pthread_mutex_unlock(&c->iolock);
615 xcb_generic_event_t *xcb_wait_for_event(xcb_connection_t *c)
617 xcb_generic_event_t *ret;
620 pthread_mutex_lock(&c->iolock);
621 /* get_event returns 0 on empty list. */
622 while(!(ret = get_event(c)))
623 if(!_xcb_conn_wait(c, &c->in.event_cond, 0, 0))
626 _xcb_in_wake_up_next_reader(c);
627 pthread_mutex_unlock(&c->iolock);
631 static xcb_generic_event_t *poll_for_next_event(xcb_connection_t *c, int queued)
633 xcb_generic_event_t *ret = 0;
636 pthread_mutex_lock(&c->iolock);
637 /* FIXME: follow X meets Z architecture changes. */
639 if(!ret && !queued && c->in.reading == 0 && _xcb_in_read(c)) /* _xcb_in_read shuts down the connection on error */
641 pthread_mutex_unlock(&c->iolock);
646 xcb_generic_event_t *xcb_poll_for_event(xcb_connection_t *c)
648 return poll_for_next_event(c, 0);
651 xcb_generic_event_t *xcb_poll_for_queued_event(xcb_connection_t *c)
653 return poll_for_next_event(c, 1);
656 xcb_generic_error_t *xcb_request_check(xcb_connection_t *c, xcb_void_cookie_t cookie)
659 xcb_generic_error_t *ret = 0;
663 pthread_mutex_lock(&c->iolock);
664 request = widen(c, cookie.sequence);
665 if(XCB_SEQUENCE_COMPARE(request, >=, c->in.request_expected)
666 && XCB_SEQUENCE_COMPARE(request, >, c->in.request_completed))
668 _xcb_out_send_sync(c);
669 _xcb_out_flush_to(c, c->out.request);
671 reply = wait_for_reply(c, request, &ret);
673 pthread_mutex_unlock(&c->iolock);
677 static xcb_generic_event_t *get_special_event(xcb_connection_t *c,
678 xcb_special_event_t *se)
680 xcb_generic_event_t *event = NULL;
681 struct event_list *events;
683 if ((events = se->events) != NULL) {
684 event = events->event;
685 if (!(se->events = events->next))
686 se->events_tail = &se->events;
692 xcb_generic_event_t *xcb_poll_for_special_event(xcb_connection_t *c,
693 xcb_special_event_t *se)
695 xcb_generic_event_t *event;
699 pthread_mutex_lock(&c->iolock);
700 event = get_special_event(c, se);
701 pthread_mutex_unlock(&c->iolock);
705 xcb_generic_event_t *xcb_wait_for_special_event(xcb_connection_t *c,
706 xcb_special_event_t *se)
708 xcb_generic_event_t *event;
712 pthread_mutex_lock(&c->iolock);
714 /* get_special_event returns 0 on empty list. */
715 while(!(event = get_special_event(c, se)))
716 if(!_xcb_conn_wait(c, &se->special_event_cond, 0, 0))
719 pthread_mutex_unlock(&c->iolock);
723 xcb_special_event_t *
724 xcb_register_for_special_xge(xcb_connection_t *c,
725 xcb_extension_t *ext,
729 xcb_special_event_t *se;
730 const xcb_query_extension_reply_t *ext_reply;
734 ext_reply = xcb_get_extension_data(c, ext);
737 pthread_mutex_lock(&c->iolock);
738 for (se = c->in.special_events; se; se = se->next) {
739 if (se->extension == ext_reply->major_opcode &&
741 pthread_mutex_unlock(&c->iolock);
745 se = calloc(1, sizeof(xcb_special_event_t));
747 pthread_mutex_unlock(&c->iolock);
751 se->extension = ext_reply->major_opcode;
755 se->events_tail = &se->events;
758 pthread_cond_init(&se->special_event_cond, 0);
760 se->next = c->in.special_events;
761 c->in.special_events = se;
762 pthread_mutex_unlock(&c->iolock);
767 xcb_unregister_for_special_event(xcb_connection_t *c,
768 xcb_special_event_t *se)
770 xcb_special_event_t *s, **prev;
771 struct event_list *events, *next;
779 pthread_mutex_lock(&c->iolock);
781 for (prev = &c->in.special_events; (s = *prev) != NULL; prev = &(s->next)) {
784 for (events = se->events; events; events = next) {
786 free (events->event);
789 pthread_cond_destroy(&se->special_event_cond);
794 pthread_mutex_unlock(&c->iolock);
797 /* Private interface */
799 int _xcb_in_init(_xcb_in *in)
801 if(pthread_cond_init(&in->event_cond, 0))
807 in->request_read = 0;
808 in->request_completed = 0;
810 in->replies = _xcb_map_new();
814 in->current_reply_tail = &in->current_reply;
815 in->events_tail = &in->events;
816 in->pending_replies_tail = &in->pending_replies;
821 void _xcb_in_destroy(_xcb_in *in)
823 pthread_cond_destroy(&in->event_cond);
824 free_reply_list(in->current_reply);
825 _xcb_map_delete(in->replies, (void (*)(void *)) free_reply_list);
828 struct event_list *e = in->events;
829 in->events = e->next;
833 while(in->pending_replies)
835 pending_reply *pend = in->pending_replies;
836 in->pending_replies = pend->next;
841 void _xcb_in_wake_up_next_reader(xcb_connection_t *c)
845 pthreadret = pthread_cond_signal(c->in.readers->data);
847 pthreadret = pthread_cond_signal(&c->in.event_cond);
848 assert(pthreadret == 0);
851 int _xcb_in_expect_reply(xcb_connection_t *c, uint64_t request, enum workarounds workaround, int flags)
853 pending_reply *pend = malloc(sizeof(pending_reply));
854 assert(workaround != WORKAROUND_NONE || flags != 0);
857 _xcb_conn_shutdown(c, XCB_CONN_CLOSED_MEM_INSUFFICIENT);
860 pend->first_request = pend->last_request = request;
861 pend->workaround = workaround;
864 *c->in.pending_replies_tail = pend;
865 c->in.pending_replies_tail = &pend->next;
869 void _xcb_in_replies_done(xcb_connection_t *c)
871 struct pending_reply *pend;
872 if (c->in.pending_replies_tail != &c->in.pending_replies)
874 pend = container_of(c->in.pending_replies_tail, struct pending_reply, next);
875 if(pend->workaround == WORKAROUND_EXTERNAL_SOCKET_OWNER)
877 pend->last_request = c->out.request;
878 pend->workaround = WORKAROUND_NONE;
883 int _xcb_in_read(xcb_connection_t *c)
889 .iov_base = c->in.queue + c->in.queue_len,
890 .iov_len = sizeof(c->in.queue) - c->in.queue_len,
893 struct cmsghdr cmsghdr;
894 char buf[CMSG_SPACE(XCB_MAX_PASS_FD * sizeof(int))];
896 struct msghdr msg = {
901 .msg_control = cmsgbuf.buf,
902 .msg_controllen = CMSG_SPACE(sizeof(int) * (XCB_MAX_PASS_FD - c->in.in_fd.nfd)),
904 n = recvmsg(c->fd, &msg, 0);
906 /* Check for truncation errors. Only MSG_CTRUNC is
907 * probably possible here, which would indicate that
908 * the sender tried to transmit more than XCB_MAX_PASS_FD
911 if (msg.msg_flags & (MSG_TRUNC|MSG_CTRUNC)) {
912 _xcb_conn_shutdown(c, XCB_CONN_CLOSED_FDPASSING_FAILED);
916 n = recv(c->fd, c->in.queue + c->in.queue_len, sizeof(c->in.queue) - c->in.queue_len, 0);
922 if (msg.msg_controllen >= sizeof (struct cmsghdr)) {
923 for (hdr = CMSG_FIRSTHDR(&msg); hdr; hdr = CMSG_NXTHDR(&msg, hdr)) {
924 if (hdr->cmsg_level == SOL_SOCKET && hdr->cmsg_type == SCM_RIGHTS) {
925 int nfd = (hdr->cmsg_len - CMSG_LEN(0)) / sizeof (int);
926 memcpy(&c->in.in_fd.fd[c->in.in_fd.nfd], CMSG_DATA(hdr), nfd * sizeof (int));
927 c->in.in_fd.nfd += nfd;
932 c->in.queue_len += n;
934 while(read_packet(c))
937 if (c->in.in_fd.nfd) {
938 c->in.in_fd.nfd -= c->in.in_fd.ifd;
939 memmove(&c->in.in_fd.fd[0],
940 &c->in.in_fd.fd[c->in.in_fd.ifd],
941 c->in.in_fd.nfd * sizeof (int));
944 /* If we have any left-over file descriptors after emptying
945 * the input buffer, then the server sent some that we weren't
946 * expecting. Close them and mark the connection as broken;
948 if (c->in.queue_len == 0 && c->in.in_fd.nfd != 0) {
950 for (i = 0; i < c->in.in_fd.nfd; i++)
951 close(c->in.in_fd.fd[i]);
952 _xcb_conn_shutdown(c, XCB_CONN_CLOSED_FDPASSING_FAILED);
958 if((n > 0) || (n < 0 && errno == EAGAIN))
960 if((n > 0) || (n < 0 && WSAGetLastError() == WSAEWOULDBLOCK))
963 _xcb_conn_shutdown(c, XCB_CONN_ERROR);
967 int _xcb_in_read_block(xcb_connection_t *c, void *buf, int len)
969 int done = c->in.queue_len;
973 memcpy(buf, c->in.queue, done);
974 c->in.queue_len -= done;
975 memmove(c->in.queue, c->in.queue + done, c->in.queue_len);
979 int ret = read_block(c->fd, (char *) buf + done, len - done);
982 _xcb_conn_shutdown(c, XCB_CONN_ERROR);