Boost.Asio的文档是不存在的。什么这些错误是什么意思? [英] Boost.Asio documentation is non-existent. What do these errors mean?
问题描述
我挣扎了两个错误与Boost.Asio的。
I'm struggling with two errors with Boost.Asio.
在第一次出现时,我尝试接收套接字数据:
The first occurs when I try to receive data on a socket:
char reply[1024];
boost::system::error_code error;
size_t reply_length = s.receive(boost::asio::buffer(reply, 1024), 0, error);
if (error) cout << error.message() << endl; //outputs "End of file"
当我尝试创建一个ip :: TCP ::从(!有效)本地插座插座时,会出现第二个:
The second occurs when I try to create an ip::tcp::socket from a (valid!) native socket:
boost::asio::io_service ioserv;
boost::asio::ip::tcp::socket s(ioserv);
boost::system::error_code error;
s.assign(boost::asio::ip::tcp::v4(), nativeSocket, error);
if (error) cout << error.message() << endl; //outputs "The parameter is incorrect"
通过所有这些麻烦的任何文档转向,我很想回去BSD插座,但我有我有自己的问题...因此,如果有人可以帮助,我真的AP preciate吧。
With all these troubles an no documentation to turn to, I am tempted to go back to BSD sockets, but I'm having my own problems there...so if anyone can help, I'd really appreciate it.
编辑:关于2号,nativeSocket是正是如此宣称:
Regarding number 2, nativeSocket is declared thusly:
SOCKET nativeSocket = INVALID_SOCKET;
nativeSocket = accept(svr_sock, (struct sockaddr*)&sin, &size);
在此之后,一些其他的事情完成到插座 - 即,将其设置为非阻塞使用ioctlsocket,以及使用的setsockopt为SO_LINGER和SO_OOBINLINE
After that, a few other things are done to the socket -- namely, setting it as non-blocking using ioctlsocket, and using setsockopt for SO_LINGER and SO_OOBINLINE.
推荐答案
这是不以任何方式向你的第二个问题的完整解决方案。它产生的任何错误应该被映射到的boost ::系统::错误_ code
,但我不升压/系统/错误_ code.hpp
,所以我无所适从,究竟什么是应该的意思。
This is not a complete solution to your second problem by any means. Any errors that it generates should be mapped into a boost::system::error_code
, but I don't find anything like it in boost/system/error_code.hpp
, so I'm at a loss as to what exactly it is supposed to mean.
不过,通过code寻找升压后的1.39,分配
最终被移交给任何详细:: reactive_socket_service&LT;协议,反应堆&GT; .assign
(或详细:: win_iocp_socket_service&LT;&协议GT;
,如果你使用的是Windows)。它只能在升压/ ASIO /细节/ reactive_socket_service.hpp被生产在两个地方的错误
:
But, after looking through the code for boost 1.39, assign
is eventually handed off to either detail::reactive_socket_service< Protocol, Reactor >.assign
(or detail::win_iocp_socket_service<Protocol>
, if you're using windows). It can only be producing an error in two places in boost/asio/detail/reactive_socket_service.hpp
:
if (is_open(impl))
{
ec = boost::asio::error::already_open;
return ec;
}
或
if (int err = reactor_.register_descriptor(
native_socket, impl.reactor_data_))
{
ec = boost::system::error_code(err,
boost::asio::error::get_system_category());
return ec;
}
一直以来,你没有得到一个 already_open
错误,错误必须从code的第二位。该堆型来源于序列的ifdef
/ ELIF
对在升压/ ASIO / stream_socket_service .HPP
,以及那些可以在 epoll_reactor
只有 register_descriptor
函数可以抛出任何错误(当然详细:: win_iocp_socket_service&LT;&协议GT; .assign
就可以了,也可以)。在 epoll_reactor
这个错误来自 SYS / epoll.h
,具体是:
Since, you're not getting an already_open
error, the error must from the second bit of code. The reactor type comes from a sequence of ifdef
/elif
pairs in boost/asio/stream_socket_service.hpp
, and of those available only the register_descriptor
function in epoll_reactor
can throw any error (and of course detail::win_iocp_socket_service<Protocol>.assign
can, also). The error in epoll_reactor
comes from sys/epoll.h
, specifically:
int result = epoll_ctl(epoll_fd_, EPOLL_CTL_ADD, descriptor, &ev);
if (result != 0)
return errno;
在Windows的实施,相关的code是
In the windows implementation, the related code is
if (iocp_service_.register_handle(native_socket.as_handle(), ec))
return ec;
我觉得这是你错误的起源,但说实话,我找不到它过去的这一点。
I think this is the origin of your error, but honestly, I can't trace it past this point.
这篇关于Boost.Asio的文档是不存在的。什么这些错误是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!