From 19f85cd9b96f291600012354ab668dbb0043c814 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 2 Jan 2007 21:20:40 +0000 Subject: r20485: Add select with a 10 second timeout when reading DSN update responses. (This used to be commit cb6c6a49e257d60318101c897e8d2b86de08a846) --- source3/libaddns/dnssock.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/source3/libaddns/dnssock.c b/source3/libaddns/dnssock.c index 2f48df1bbd..5dbedc4fd5 100644 --- a/source3/libaddns/dnssock.c +++ b/source3/libaddns/dnssock.c @@ -213,15 +213,29 @@ DNS_ERROR dns_send(struct dns_connection *conn, const struct dns_buffer *buf) static DNS_ERROR read_all(int fd, uint8 *data, size_t len) { size_t total = 0; + fd_set rfds; + struct timeval tv; while (total < len) { + ssize_t ret; + int fd_ready; + + FD_ZERO( &rfds ); + FD_SET( fd, &rfds ); + + /* 10 second timeout */ + tv.tv_sec = 10; + tv.tv_usec = 0; + + fd_ready = select( fd+1, &rfds, NULL, NULL, &tv ); + if ( fd_ready == 0 ) { + /* read timeout */ + return ERROR_DNS_SOCKET_ERROR; + } - ssize_t ret = read(fd, data + total, len - total); - + ret = read(fd, data + total, len - total); if (ret <= 0) { - /* - * EOF or error - */ + /* EOF or error */ return ERROR_DNS_SOCKET_ERROR; } -- cgit