POCO HTTPClientSession 结构

在这里插入图片描述
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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值