diff --git a/uppsrc/Core/Http.cpp b/uppsrc/Core/Http.cpp index 5b5e7b3f4..0083e00a0 100644 --- a/uppsrc/Core/Http.cpp +++ b/uppsrc/Core/Http.cpp @@ -218,6 +218,13 @@ void HttpRequest::StartPhase(int s) data.Clear(); } +void HttpRequest::New() +{ + ClearError(); + ClearAbort(); + phase = BEGIN; +} + bool HttpRequest::Do() { int c1, c2; @@ -282,6 +289,7 @@ bool HttpRequest::Do() break; case FINISHED: case FAILED: + WhenDo(); return false; default: NEVER(); @@ -308,6 +316,7 @@ bool HttpRequest::Do() StartPhase(START); } } + WhenDo(); return phase != FINISHED && phase != FAILED; } @@ -326,14 +335,21 @@ void HttpRequest::Start() p = ssl ? DEFAULT_HTTPS_PORT : DEFAULT_HTTP_PORT; String h = use_proxy ? ssl ? ssl_proxy_host : proxy_host : host; + StartPhase(DNS); if(IsNull(GetTimeout())) { - addrinfo.Execute(h, p); + if(WhenWait) { + addrinfo.Start(h, p); + while(addrinfo.InProgress()) { + Sleep(GetWaitStep()); + WhenWait(); + } + } + else + addrinfo.Execute(h, p); StartConnect(); } - else { + else addrinfo.Start(h, p); - StartPhase(DNS); - } } void HttpRequest::Dns() diff --git a/uppsrc/Core/Inet.h b/uppsrc/Core/Inet.h index 04a7d7dbf..0c4937bf3 100644 --- a/uppsrc/Core/Inet.h +++ b/uppsrc/Core/Inet.h @@ -200,6 +200,8 @@ public: TcpSocket& Timeout(int ms) { timeout = ms; return *this; } int GetTimeout() const { return timeout; } TcpSocket& Blocking() { return Timeout(Null); } + TcpSocket& WaitStep(int ms) { waitstep = ms; return *this; } + int GetWaitStep() const { return waitstep; } TcpSocket(); ~TcpSocket() { Close(); } @@ -336,6 +338,7 @@ class HttpRequest : public TcpSocket { public: Callback2 WhenContent; + Callback WhenDo; HttpRequest& MaxHeaderSize(int m) { max_header_size = m; return *this; } HttpRequest& MaxContentSize(int m) { max_content_size = m; return *this; } @@ -419,6 +422,8 @@ public: bool IsSuccess() const { return phase == FINISHED && status_code >= 200 && status_code < 300; } String Execute(); + + void New(); HttpRequest(); HttpRequest(const char *url); diff --git a/uppsrc/Core/Socket.cpp b/uppsrc/Core/Socket.cpp index 8062bc94d..a23a3c7d1 100644 --- a/uppsrc/Core/Socket.cpp +++ b/uppsrc/Core/Socket.cpp @@ -268,7 +268,7 @@ TcpSocket::TcpSocket() ClearError(); Reset(); timeout = Null; - waitstep = 20; + waitstep = 10; asn1 = false; }