- if (revents & (EPOLLIN|EPOLLHUP|EPOLLRDHUP)) {
-
- if (t->tcp_read < sizeof(t->tcp_read_size)) {
- ssize_t ss;
-
- ss = read(fd, (uint8_t*) &t->tcp_read_size + t->tcp_read, sizeof(t->tcp_read_size) - t->tcp_read);
- if (ss < 0) {
- if (errno != EINTR && errno != EAGAIN) {
- dns_query_transaction_complete(t, DNS_QUERY_RESOURCES);
- return -errno;
- }
- } else if (ss == 0) {
- dns_query_transaction_complete(t, DNS_QUERY_RESOURCES);
- return -EIO;
- } else
- t->tcp_read += ss;
- }
-
- if (t->tcp_read >= sizeof(t->tcp_read_size)) {
-
- if (be16toh(t->tcp_read_size) < DNS_PACKET_HEADER_SIZE) {
- dns_query_transaction_complete(t, DNS_QUERY_INVALID_REPLY);
- return -EBADMSG;
- }
-
- if (t->tcp_read < sizeof(t->tcp_read_size) + be16toh(t->tcp_read_size)) {
- ssize_t ss;
-
- if (!t->received) {
- r = dns_packet_new(&t->received, t->scope->protocol, be16toh(t->tcp_read_size));
- if (r < 0) {
- dns_query_transaction_complete(t, DNS_QUERY_RESOURCES);
- return r;
- }
- }
-
- ss = read(fd,
- (uint8_t*) DNS_PACKET_DATA(t->received) + t->tcp_read - sizeof(t->tcp_read_size),
- sizeof(t->tcp_read_size) + be16toh(t->tcp_read_size) - t->tcp_read);
- if (ss < 0) {
- if (errno != EINTR && errno != EAGAIN) {
- dns_query_transaction_complete(t, DNS_QUERY_RESOURCES);
- return -errno;
- }
- } else if (ss == 0) {
- dns_query_transaction_complete(t, DNS_QUERY_RESOURCES);
- return -EIO;
- } else
- t->tcp_read += ss;
- }