您可以设置在升压ASIO SO_RCVTIMEO和SO_SNDTIMEO套接字选项? [英] can you set SO_RCVTIMEO and SO_SNDTIMEO socket options in boost asio?
问题描述
您可以在升压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.
推荐答案
当然!提高ASIO允许您访问本机/基础数据,在这种情况下是插座本身。所以,让我们说你有:
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;
和假设你已经叫打开
或绑定
或实际上使一些成员函数 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.
这篇关于您可以设置在升压ASIO SO_RCVTIMEO和SO_SNDTIMEO套接字选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!