1、HttpSession 超时设置
如果只设置1个值,那么是所有的,也可以分开设置
void HTTPSession::setTimeout(const Poco::Timespan& timeout)
{
setTimeout(timeout, timeout, timeout);
}
void HTTPSession::setTimeout(const Poco::Timespan& connectionTimeout, const Poco::Timespan& sendTimeout, const Poco::Timespan& receiveTimeout)
{
_connectionTimeout = connectionTimeout;
_sendTimeout = sendTimeout;
_receiveTimeout = receiveTimeout;
}
void SocketImpl::setSendTimeout(const Poco::Timespan& timeout)
{
#if defined(_WIN32) && !defined(POCO_BROKEN_TIMEOUTS)
int value = (int) timeout.totalMilliseconds();
setOption(SOL_SOCKET, SO_SNDTIMEO, value);
#elif !defined(POCO_BROKEN_TIMEOUTS)
setOption(SOL_SOCKET, SO_SNDTIMEO, timeout);
#endif
if (_isBrokenTimeout)
_sndTimeout = timeout;
}
SO_RCVTIMEO和SO_SNDTIMEO ,它们分别用来设置socket接收数据超时时间和发送数据超时时间。
因此,这两个选项仅对与数据收发相关的系统调用有效,这些系统调用包括:send, sendmsg, recv, recvmsg, accept, connect 。
这两个选项设置后,若超时, 返回-1,并设置errno为EAGAIN或EWOULDBLOCK.
其中connect超时的话,也是返回-1, 但errno设置为EINPROGRESS
参考 https://blog.csdn.net/jasonliuvip/article/details/23567843
2、保持连接设置
HTTPSClientSession 与HTTPRequest 的 保持连接区别
s.setKeepAlive(true);
理解为保持连接的开关,如果要保持连接,必须 同时使用 request.setKeepAlive(true);
如果没有这个的话,肯定不是保持连接
request.setKeepAlive(true);
文件头中增加 “Connection” Keep-Alive
1、什么是Keep-Alive模式?
我们知道HTTP协议采用“请求-应答”模式,当使用普通模式,即非KeepAlive模式时,每个请求/应答客户和服务器都要新建一个连接,完成之后立即断开连接(HTTP协议为无连接的协议);当使用Keep-Alive模式(又称持久连接、连接重用)时,Keep-Alive功能使客户端到服务器端的连接持续有效,当出现对服务器的后继请求时,Keep-Alive功能避免了建立或者重新建立连接。
参考 https://blog.csdn.net/charleslei/article/details/50621912