Skip to content

Commit 3aa28bc

Browse files
committedDec 24, 2013
Use sleep_ms instead of select in httpfetch when max_fd == -1, fixes WSAEINVAL
1 parent a537725 commit 3aa28bc

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed
 

‎src/httpfetch.cpp

+21-13
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
1818
*/
1919

2020
#include "socket.h" // for select()
21+
#include "porting.h" // for sleep_ms()
2122
#include "httpfetch.h"
2223
#include <iostream>
2324
#include <sstream>
@@ -520,19 +521,26 @@ class CurlFetchThread : public JThread
520521
select_timeout = timeout;
521522

522523
if (select_timeout > 0) {
523-
select_tv.tv_sec = select_timeout / 1000;
524-
select_tv.tv_usec = (select_timeout % 1000) * 1000;
525-
int retval = select(max_fd + 1, &read_fd_set,
526-
&write_fd_set, &exc_fd_set,
527-
&select_tv);
528-
if (retval == -1) {
529-
#ifdef _WIN32
530-
errorstream<<"select returned error code "
531-
<<WSAGetLastError()<<std::endl;
532-
#else
533-
errorstream<<"select returned error code "
534-
<<errno<<std::endl;
535-
#endif
524+
// in Winsock it is forbidden to pass three empty
525+
// fd_sets to select(), so in that case use sleep_ms
526+
if (max_fd == -1) {
527+
select_tv.tv_sec = select_timeout / 1000;
528+
select_tv.tv_usec = (select_timeout % 1000) * 1000;
529+
int retval = select(max_fd + 1, &read_fd_set,
530+
&write_fd_set, &exc_fd_set,
531+
&select_tv);
532+
if (retval == -1) {
533+
#ifdef _WIN32
534+
errorstream<<"select returned error code "
535+
<<WSAGetLastError()<<std::endl;
536+
#else
537+
errorstream<<"select returned error code "
538+
<<errno<<std::endl;
539+
#endif
540+
}
541+
}
542+
else {
543+
sleep_ms(select_timeout);
536544
}
537545
}
538546
}

0 commit comments

Comments
 (0)
Please sign in to comment.