/** handle ssl tcp connection with dns contents */
static int
-ssl_handle_it(struct comm_point* c)
+ssl_handle_it(struct comm_point* c, int is_write)
{
- if(c->tcp_is_reading)
+ /* handle case where renegotiation wants read during write call
+ * or write during read calls */
+ if(is_write && c->ssl_shake_state == comm_ssl_shake_hs_write)
+ return ssl_handle_read(c);
+ else if(!is_write && c->ssl_shake_state == comm_ssl_shake_hs_read)
+ return ssl_handle_write(c);
+ /* handle read events for read operation and write events for a
+ * write operation */
+ else if(!is_write)
return ssl_handle_read(c);
return ssl_handle_write(c);
}
{
ssize_t r;
log_assert(c->type == comm_tcp || c->type == comm_local);
+ verbose(5, "comm point tcp handle read fd %d", fd);
if(c->ssl)
- return ssl_handle_it(c);
- if(!c->tcp_is_reading)
+ return ssl_handle_it(c, 0);
+ if(!c->tcp_is_reading && !c->tcp_write_and_read)
return 0;
log_assert(fd != -1);
#else
buffer = c->buffer;
#endif
- if(c->tcp_is_reading && !c->ssl)
+ verbose(5, "comm point tcp handle write fd %d", fd);
+ if(c->tcp_is_reading && !c->ssl && !c->tcp_write_and_read)
return 0;
+ verbose(5, "comm point tcp handle write fd %d, part2", fd);
log_assert(fd != -1);
if(((!c->tcp_write_and_read && c->tcp_byte_count == 0) || (c->tcp_write_and_read && c->tcp_write_byte_count == 0)) && c->tcp_check_nb_connect) {
/* check for pending error from nonblocking connect */
return 0;
}
}
+ verbose(5, "comm point tcp handle write fd %d, part3", fd);
if(c->ssl)
- return ssl_handle_it(c);
+ return ssl_handle_it(c, 1);
+ verbose(5, "comm point tcp handle write fd %d, part4", fd);
#ifdef USE_MSG_FASTOPEN
/* Only try this on first use of a connection that uses tfo,
}
#endif /* USE_MSG_FASTOPEN */
+ verbose(5, "comm point tcp handle write fd %d: before write", fd);
if((c->tcp_write_and_read?c->tcp_write_byte_count:c->tcp_byte_count) < sizeof(uint16_t)) {
uint16_t len = htons(c->tcp_write_and_read?c->tcp_write_pkt_len:sldns_buffer_limit(buffer));
#ifdef HAVE_WRITEV
sizeof(uint16_t)-c->tcp_byte_count, 0);
}
#endif /* HAVE_WRITEV */
+ verbose(5, "comm point tcp handle write fd %d: write res %d", fd, (int)r);
if(r == -1) {
#ifndef USE_WINSOCK
# ifdef EPIPE
}
log_assert(c->tcp_write_and_read || sldns_buffer_remaining(buffer) > 0);
log_assert(!c->tcp_write_and_read || c->tcp_write_byte_count < c->tcp_write_pkt_len + 2);
+ verbose(5, "comm point tcp handle write fd %d: before write remain", fd);
if(c->tcp_write_and_read) {
r = send(fd, (void*)c->tcp_write_pkt + c->tcp_write_byte_count - 2,
c->tcp_write_pkt_len + 2 - c->tcp_write_byte_count, 0);
r = send(fd, (void*)sldns_buffer_current(buffer),
sldns_buffer_remaining(buffer), 0);
}
+ verbose(5, "comm point tcp handle write fd %d: write remain res %d", fd, (int)r);
if(r == -1) {
#ifndef USE_WINSOCK
if(errno == EINTR || errno == EAGAIN)