#include <Core/Core.h> using namespace Upp; CONSOLE_APP_MAIN { HttpRequest::Trace(true); HttpRequest http("http://google.com"); //fails with almost any sites even w/o redirect String s = http.Execute(); SaveFile("1", s); }
Quote: |
HTTP START Starting status 2 'Resolving host name', url: google.com HTTP StartConnect HTTP AfterConnect Starting status 6 'Sending request', url: google.com HTTP REQUEST google.com:0 HTTP request: GET / HTTP/1.1 URL: http://google.com/ Host: google.com Connection: close Accept: */* Accept-Encoding: gzip User-Agent: U++ HTTP request HTTP Execute: Sending request HTTP retry on error socket(5) / send: Socket is not connected Starting status 1 'Start', url: google.com HTTP Execute: Start HTTP START Starting status 2 'Resolving host name', url: google.com HTTP StartConnect HTTP AfterConnect Starting status 6 'Sending request', url: google.com HTTP REQUEST google.com:0 HTTP request: GET / HTTP/1.1 URL: http://google.com/ Host: google.com Connection: close Accept: */* Accept-Encoding: gzip User-Agent: U++ HTTP request HTTP Execute: Sending request HTTP retry on error socket(5) / send: Socket is not connected Starting status 1 'Start', url: google.com HTTP Execute: Start HTTP START Starting status 2 'Resolving host name', url: google.com HTTP StartConnect HTTP AfterConnect Starting status 6 'Sending request', url: google.com HTTP REQUEST google.com:0 HTTP request: GET / HTTP/1.1 URL: http://google.com/ Host: google.com Connection: close Accept: */* Accept-Encoding: gzip User-Agent: U++ HTTP request HTTP Execute: Sending request HTTP retry on error socket(5) / send: Socket is not connected Starting status 1 'Start', url: google.com HTTP Execute: Start HTTP START Starting status 2 'Resolving host name', url: google.com HTTP StartConnect HTTP AfterConnect Starting status 6 'Sending request', url: google.com HTTP REQUEST google.com:0 HTTP request: GET / HTTP/1.1 URL: http://google.com/ Host: google.com Connection: close Accept: */* Accept-Encoding: gzip User-Agent: U++ HTTP request HTTP Execute: Sending request |
bool HttpRequest::Do() { Sleep(10); // <-- delay added, and the code works int c1, c2; switch(phase) {
HttpRequest http("http://google.com"); String s = http.Execute();
(Core/Socket.spp) bool TcpSocket::RawConnect(addrinfo *arp) ... //@445 +++ if (GetErrorCode() == SOCKERR(EINPROGRESS)) WaitWrite(); // +++
(Core/Socket.spp) bool TcpSocket::RawConnect(addrinfo *arp) ... //@445 +++ if (GetErrorCode() == SOCKERR(EINPROGRESS)) WaitWrite(); // +++
bool TcpSocket::WouldBlock() { int c = GetErrorCode(); #ifdef PLATFORM_POSIX #ifdef PLATFORM_BSD if(c == SOCKERR(ENOTCONN)) return true; #endif return c == SOCKERR(EWOULDBLOCK) || c == SOCKERR(EAGAIN); #endif #ifdef PLATFORM_WIN32 if(c == SOCKERR(ENOTCONN) && !IsNull(connection_start) && msecs(connection_start) < 20000) { LLOG("ENOTCONN issue"); return true; } return c == SOCKERR(EWOULDBLOCK); #endif }
Index: Socket.cpp =================================================================== --- Socket.cpp (revision 5727) +++ Socket.cpp (working copy) @@ -268,7 +268,7 @@ sslinfo.Clear(); start_time = Null; global_timeout = Null; -#ifdef PLATFORM_WIN32 +#if (PLATFORM_WIN32 || PLATFORM_BSD) connection_start = Null; #endif ssl_start = Null; @@ -293,6 +293,9 @@ return false; } #else + #if (PLATFORM_BSD) + connection_start = msecs(); + #endif if(fcntl(socket, F_SETFL, (fcntl(socket, F_GETFL, 0) | O_NONBLOCK))) { SetSockError("fcntl(O_[NON]BLOCK)"); return false; @@ -509,7 +512,12 @@ { int c = GetErrorCode(); #ifdef PLATFORM_POSIX - return c == SOCKERR(EWOULDBLOCK) || c == SOCKERR(EAGAIN); + #ifdef PLATFORM_BSD + DUMP(connection_start); + if(c == SOCKERR(ENOTCONN) && !IsNull(connection_start) && msecs(connection_start) < 20000) + return true; + #endif + return c == c == SOCKERR(EWOULDBLOCK) || c == SOCKERR(EAGAIN); #endif #ifdef PLATFORM_WIN32 if(c == SOCKERR(ENOTCONN) && !IsNull(connection_start) && msecs(connection_start) < 20000) { @@ -599,7 +607,7 @@ return false; } if(avail > 0) { - #ifdef PLATFORM_WIN32 + #if (PLATFORM_WIN32 || PLATFORM_BSD) connection_start = Null; #endif return true; @@ -630,7 +638,7 @@ { // Compute time limit for operation, based on global timeout and per-operation timeout settings int o = min(IsNull(global_timeout) ? INT_MAX : start_time + global_timeout, IsNull(timeout) ? INT_MAX : msecs() + timeout); -#ifdef PLATFORM_WIN32 +#if (PLATFORM_WIN32 || PLATFORM_BSD) if(GetErrorCode() == SOCKERR(ENOTCONN) && !IsNull(connection_start)) if(msecs(connection_start) < 20000) o = connection_start + 20000; Index: Inet.h =================================================================== --- Inet.h (revision 5727) +++ Inet.h (working copy) @@ -88,7 +88,7 @@ int global_timeout; int start_time; -#ifdef PLATFORM_WIN32 +#if (PLATFORM_WIN32 || PLATFORM_BSD) int connection_start; #endif int ssl_start;
return c == c == SOCKERR(EWOULDBLOCK) || c == SOCKERR(EAGAIN);