From a53ee58746ea6247169fbf86e7b8e3ed81c1eb40 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 25 Apr 2010 13:49:31 +0000 Subject: 2010-04-25 Tatsuhiro Tsujikawa Print warning when trying to add file descriptor >= FD_SET or < 0 to fd_set for other than MinGW32 build. For MinGW32 build, print warning when trying to add file descriptor to fd_set when it already contains FD_SET file descriptors. * src/SelectEventPoll.cc * src/SocketCore.cc --- src/SocketCore.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/SocketCore.cc') diff --git a/src/SocketCore.cc b/src/SocketCore.cc index c35b6f13..3cc7374a 100644 --- a/src/SocketCore.cc +++ b/src/SocketCore.cc @@ -546,6 +546,14 @@ void SocketCore::closeConnection() #endif // HAVE_LIBGNUTLS } +#ifndef __MINGW32__ +# define CHECK_FD(fd) \ + if(fd < 0 || FD_SETSIZE <= fd) { \ + _logger->warn("Detected file descriptor >= FD_SETSIZE or < 0. " \ + "Download may slow down or fail."); \ + return false; \ + } +#endif // !__MINGW32__ bool SocketCore::isWritable(time_t timeout) { @@ -564,6 +572,9 @@ bool SocketCore::isWritable(time_t timeout) (StringFormat(EX_SOCKET_CHECK_WRITABLE, errorMsg()).str()); } #else // !HAVE_POLL +# ifndef __MINGW32__ + CHECK_FD(sockfd); +# endif // !__MINGW32__ fd_set fds; FD_ZERO(&fds); FD_SET(sockfd, &fds); @@ -611,6 +622,9 @@ bool SocketCore::isReadable(time_t timeout) (StringFormat(EX_SOCKET_CHECK_READABLE, errorMsg()).str()); } #else // !HAVE_POLL +# ifndef __MINGW32__ + CHECK_FD(sockfd); +# endif // !__MINGW32__ fd_set fds; FD_ZERO(&fds); FD_SET(sockfd, &fds); -- cgit