can you set SO_RCVTIMEO and SO_SNDTIMEO socket options in boost asio?(你能在 boost asio 中设置 SO_RCVTIMEO 和 SO_SNDTIMEO 套接字选项吗?)
问题描述
你能在 boost asio 中设置 SO_RCVTIMEO 和 SO_SNDTIMEO 套接字选项吗?
can you set SO_RCVTIMEO and SO_SNDTIMEO socket options in boost asio?
如果有,怎么办?
注意我知道你可以使用定时器来代替,但我想特别了解这些套接字选项.
Note I know you can use timers instead, but I'd like to know about these socket options in particular.
推荐答案
当然可以!Boost ASIO 允许您访问本机/底层数据,在这种情况下是 SOCKET 本身.所以,假设您有:
Absolutely! Boost ASIO allows you to access the native/underlying data, which in this case is the SOCKET itself. So, let's say you have:
boost::asio::ip::tcp::socket my_socket;
假设您已经调用了 open 或 bind 或一些实际上使 my_socket 可用的成员函数.然后,要获取底层 SOCKET 值,请调用:
And let's say you've already called open or bind or some member function that actually makes my_socket usable. Then, to get the underlying SOCKET value, call:
SOCKET native_sock = my_socket.native();
int result = SOCKET_ERROR;
if (INVALID_SOCKET != native_sock)
{
result = setsockopt(native_sock, SOL_SOCKET, <the pertinent params you want to use>);
}
所以你有它!Boost 的 ASIO 使您可以比其他方式更快地完成许多事情,但仍有很多事情您仍然需要正常的套接字库调用.这恰好是其中之一.
So there you have it! Boost's ASIO lets you do many things more quickly than you otherwise might be able to, but there are a lot of things you still need the normal socket library calls for. This happens to be one of them.
这篇关于你能在 boost asio 中设置 SO_RCVTIMEO 和 SO_SNDTIMEO 套接字选项吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:你能在 boost asio 中设置 SO_RCVTIMEO 和 SO_SNDTIMEO 套接字选项吗?
基础教程推荐
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- CString 到 char* 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
