Loading src/http.cpp +9 −22 Original line number Diff line number Diff line Loading @@ -389,31 +389,18 @@ void libhttppp::HttpClient::resetConnection(){ } } // Plain-TCP connect bounded by _recvTimeoutSec instead of the OS default // connect timeout (which can be minutes) -- a fully unreachable host (dead // container, wrong IP, dropped SYNs) would otherwise hang the caller far // longer than any configured setTimeout() would suggest. void libhttppp::HttpClient::_connectTcp(netplus::socket &sock) { // Bounded by _recvTimeoutSec instead of the OS default connect timeout // (which can be minutes) -- a fully unreachable host (dead container, // wrong IP, dropped SYNs) would otherwise hang the caller far longer than // any configured setTimeout() would suggest. The actual non-blocking // connect/waitWrite/SO_ERROR dance lives in netplus::tcp::connectTimeout() // so any direct netplus::tcp consumer can reuse it too. void libhttppp::HttpClient::_connectTcp(netplus::tcp &sock) { try { sock.connect(_url.getHost(), _url.getPort(), true); // Connected immediately (rare for TCP, but handle it) return; sock.connectTimeout(_url.getHost(), _url.getPort(), _recvTimeoutSec * 1000); } catch (netplus::NetException &e) { if (e.getErrorType() != netplus::NetException::Note) throw; } if (!_sw.waitWrite(sock, _recvTimeoutSec * 1000)) { HTTPException he; he[HTTPException::Error] << "tcp connect timeout after " << _recvTimeoutSec << "s"; throw he; } int err = 0; socklen_t errlen = sizeof(err); if (::getsockopt(sock.fd(), SOL_SOCKET, SO_ERROR, &err, &errlen) != 0 || err != 0) { HTTPException he; he[HTTPException::Error] << "tcp connect failed: " << strerror(err); he[HTTPException::Error] << e.what(); throw he; } } Loading src/http.h +3 −4 Original line number Diff line number Diff line Loading @@ -150,10 +150,9 @@ namespace libhttppp { static netplus::TlsSessionCache& tlsSessionCache(); private: void _ensureConnected(); // Non-blocking connect + waitWrite, bounded by _recvTimeoutSec, so an // unreachable host (dead container, wrong IP, dropped SYNs) fails // within the configured timeout instead of the OS default (minutes). void _connectTcp(netplus::socket &sock); // Thin wrapper around netplus::tcp::connectTimeout() using // _recvTimeoutSec, translating its NetException into HTTPException. void _connectTcp(netplus::tcp &sock); bool tryHttp3First(); int readchunk(const char *data,int datasize,int &pos); Loading Loading
src/http.cpp +9 −22 Original line number Diff line number Diff line Loading @@ -389,31 +389,18 @@ void libhttppp::HttpClient::resetConnection(){ } } // Plain-TCP connect bounded by _recvTimeoutSec instead of the OS default // connect timeout (which can be minutes) -- a fully unreachable host (dead // container, wrong IP, dropped SYNs) would otherwise hang the caller far // longer than any configured setTimeout() would suggest. void libhttppp::HttpClient::_connectTcp(netplus::socket &sock) { // Bounded by _recvTimeoutSec instead of the OS default connect timeout // (which can be minutes) -- a fully unreachable host (dead container, // wrong IP, dropped SYNs) would otherwise hang the caller far longer than // any configured setTimeout() would suggest. The actual non-blocking // connect/waitWrite/SO_ERROR dance lives in netplus::tcp::connectTimeout() // so any direct netplus::tcp consumer can reuse it too. void libhttppp::HttpClient::_connectTcp(netplus::tcp &sock) { try { sock.connect(_url.getHost(), _url.getPort(), true); // Connected immediately (rare for TCP, but handle it) return; sock.connectTimeout(_url.getHost(), _url.getPort(), _recvTimeoutSec * 1000); } catch (netplus::NetException &e) { if (e.getErrorType() != netplus::NetException::Note) throw; } if (!_sw.waitWrite(sock, _recvTimeoutSec * 1000)) { HTTPException he; he[HTTPException::Error] << "tcp connect timeout after " << _recvTimeoutSec << "s"; throw he; } int err = 0; socklen_t errlen = sizeof(err); if (::getsockopt(sock.fd(), SOL_SOCKET, SO_ERROR, &err, &errlen) != 0 || err != 0) { HTTPException he; he[HTTPException::Error] << "tcp connect failed: " << strerror(err); he[HTTPException::Error] << e.what(); throw he; } } Loading
src/http.h +3 −4 Original line number Diff line number Diff line Loading @@ -150,10 +150,9 @@ namespace libhttppp { static netplus::TlsSessionCache& tlsSessionCache(); private: void _ensureConnected(); // Non-blocking connect + waitWrite, bounded by _recvTimeoutSec, so an // unreachable host (dead container, wrong IP, dropped SYNs) fails // within the configured timeout instead of the OS default (minutes). void _connectTcp(netplus::socket &sock); // Thin wrapper around netplus::tcp::connectTimeout() using // _recvTimeoutSec, translating its NetException into HTTPException. void _connectTcp(netplus::tcp &sock); bool tryHttp3First(); int readchunk(const char *data,int datasize,int &pos); Loading