| @@ -1015,53 +1015,54 @@ int _xcb_in_read(xcb_connection_t *c) | | | @@ -1015,53 +1015,54 @@ int _xcb_in_read(xcb_connection_t *c) |
1015 | #if HAVE_SENDMSG | | 1015 | #if HAVE_SENDMSG |
1016 | struct cmsghdr *hdr; | | 1016 | struct cmsghdr *hdr; |
1017 | | | 1017 | |
1018 | if (msg.msg_controllen >= sizeof (struct cmsghdr)) { | | 1018 | if (msg.msg_controllen >= sizeof (struct cmsghdr)) { |
1019 | for (hdr = CMSG_FIRSTHDR(&msg); hdr; hdr = CMSG_NXTHDR(&msg, hdr)) { | | 1019 | for (hdr = CMSG_FIRSTHDR(&msg); hdr; hdr = CMSG_NXTHDR(&msg, hdr)) { |
1020 | if (hdr->cmsg_level == SOL_SOCKET && hdr->cmsg_type == SCM_RIGHTS) { | | 1020 | if (hdr->cmsg_level == SOL_SOCKET && hdr->cmsg_type == SCM_RIGHTS) { |
1021 | int nfd = (hdr->cmsg_len - CMSG_LEN(0)) / sizeof (int); | | 1021 | int nfd = (hdr->cmsg_len - CMSG_LEN(0)) / sizeof (int); |
1022 | memcpy(&c->in.in_fd.fd[c->in.in_fd.nfd], CMSG_DATA(hdr), nfd * sizeof (int)); | | 1022 | memcpy(&c->in.in_fd.fd[c->in.in_fd.nfd], CMSG_DATA(hdr), nfd * sizeof (int)); |
1023 | c->in.in_fd.nfd += nfd; | | 1023 | c->in.in_fd.nfd += nfd; |
1024 | } | | 1024 | } |
1025 | } | | 1025 | } |
1026 | } | | 1026 | } |
1027 | #endif | | 1027 | #endif |
| | | 1028 | c->in.total_read += n; |
1028 | c->in.queue_len += n; | | 1029 | c->in.queue_len += n; |
1029 | } | | 1030 | } |
1030 | while(read_packet(c)) | | 1031 | while(read_packet(c)) |
1031 | /* empty */; | | 1032 | /* empty */; |
1032 | #if HAVE_SENDMSG | | 1033 | #if HAVE_SENDMSG |
1033 | if (c->in.in_fd.nfd) { | | 1034 | if (c->in.in_fd.nfd) { |
1034 | c->in.in_fd.nfd -= c->in.in_fd.ifd; | | 1035 | c->in.in_fd.nfd -= c->in.in_fd.ifd; |
1035 | memmove(&c->in.in_fd.fd[0], | | 1036 | memmove(&c->in.in_fd.fd[0], |
1036 | &c->in.in_fd.fd[c->in.in_fd.ifd], | | 1037 | &c->in.in_fd.fd[c->in.in_fd.ifd], |
1037 | c->in.in_fd.nfd * sizeof (int)); | | 1038 | c->in.in_fd.nfd * sizeof (int)); |
1038 | c->in.in_fd.ifd = 0; | | 1039 | c->in.in_fd.ifd = 0; |
1039 | | | 1040 | |
1040 | /* If we have any left-over file descriptors after emptying | | 1041 | /* If we have any left-over file descriptors after emptying |
1041 | * the input buffer, then the server sent some that we weren't | | 1042 | * the input buffer, then the server sent some that we weren't |
1042 | * expecting. Close them and mark the connection as broken; | | 1043 | * expecting. Close them and mark the connection as broken; |
1043 | */ | | 1044 | */ |
1044 | if (c->in.queue_len == 0 && c->in.in_fd.nfd != 0) { | | 1045 | if (c->in.queue_len == 0 && c->in.in_fd.nfd != 0) { |
1045 | int i; | | 1046 | int i; |
1046 | for (i = 0; i < c->in.in_fd.nfd; i++) | | 1047 | for (i = 0; i < c->in.in_fd.nfd; i++) |
1047 | close(c->in.in_fd.fd[i]); | | 1048 | close(c->in.in_fd.fd[i]); |
1048 | _xcb_conn_shutdown(c, XCB_CONN_CLOSED_FDPASSING_FAILED); | | 1049 | _xcb_conn_shutdown(c, XCB_CONN_CLOSED_FDPASSING_FAILED); |
1049 | return 0; | | 1050 | return 0; |
1050 | } | | 1051 | } |
1051 | } | | 1052 | } |
1052 | #endif | | 1053 | #endif |
1053 | #ifndef _WIN32 | | 1054 | #ifndef _WIN32 |
1054 | if((n > 0) || (n < 0 && errno == EAGAIN)) | | 1055 | if((n > 0) || (n < 0 && (errno == EAGAIN || errno == EINTR))) |
1055 | #else | | 1056 | #else |
1056 | if((n > 0) || (n < 0 && WSAGetLastError() == WSAEWOULDBLOCK)) | | 1057 | if((n > 0) || (n < 0 && WSAGetLastError() == WSAEWOULDBLOCK)) |
1057 | #endif /* !_WIN32 */ | | 1058 | #endif /* !_WIN32 */ |
1058 | return 1; | | 1059 | return 1; |
1059 | _xcb_conn_shutdown(c, XCB_CONN_ERROR); | | 1060 | _xcb_conn_shutdown(c, XCB_CONN_ERROR); |
1060 | return 0; | | 1061 | return 0; |
1061 | } | | 1062 | } |
1062 | | | 1063 | |
1063 | int _xcb_in_read_block(xcb_connection_t *c, void *buf, int len) | | 1064 | int _xcb_in_read_block(xcb_connection_t *c, void *buf, int len) |
1064 | { | | 1065 | { |
1065 | int done = c->in.queue_len; | | 1066 | int done = c->in.queue_len; |
1066 | if(len < done) | | 1067 | if(len < done) |
1067 | done = len; | | 1068 | done = len; |