diff --git a/include/fdlist.h b/include/fdlist.h index 571899cdf..e6da24c5b 100644 --- a/include/fdlist.h +++ b/include/fdlist.h @@ -24,6 +24,7 @@ extern MODVAR FDEntry fd_table[MAXCONNECTIONS + 1]; extern int fd_open(int fd, const char *desc); extern void fd_close(int fd); +extern int fd_unmap(int fd); extern void fd_unnotify(int fd); extern int fd_socket(int family, int type, int protocol, const char *desc); extern int fd_accept(int sockfd); diff --git a/src/fdlist.c b/src/fdlist.c index 0051d4efa..f62a69574 100644 --- a/src/fdlist.c +++ b/src/fdlist.c @@ -89,7 +89,7 @@ int fd_fileopen(const char *path, unsigned int flags) return fd_open(fd, comment); } -void fd_close(int fd) +int fd_unmap(int fd) { FDEntry *fde; unsigned int befl; @@ -100,7 +100,7 @@ void fd_close(int fd) fd, MAXCONNECTIONS); ircd_log(LOG_ERROR, "[BUG] trying to close fd #%d in fd table, but MAXCONNECTIONS is %d", fd, MAXCONNECTIONS); - return; + return 0; } fde = &fd_table[fd]; @@ -110,7 +110,7 @@ void fd_close(int fd) fd); ircd_log(LOG_ERROR, "[BUG] trying to close fd #%d in fd table, but this FD isn't reported open", fd); - return; + return 0; } befl = fde->backend_flags; @@ -121,6 +121,17 @@ void fd_close(int fd) /* only notify the backend if it is actively tracking the FD */ if (befl) fd_refresh(fd); + + return 1; +} + +void fd_close(int fd) +{ + FDEntry *fde; + unsigned int befl; + + if (!fd_unmap(fd)) + return; CLOSE_SOCK(fd); } diff --git a/src/res.c b/src/res.c index ef9fb0960..a442e9cea 100644 --- a/src/res.c +++ b/src/res.c @@ -105,6 +105,15 @@ static void unrealdns_sock_state_cb(void *data, ares_socket_t fd, int read, int { int selflags = 0; + if (!read && !write) + { + /* Socket is going to be closed *BY C-ARES*.. + * so don't call fd_close() but fd_unmap(). + */ + fd_close(fd); +// return; + } + if (read) selflags |= FD_SELECT_READ;