Boost::asio::socket 如何从中获取可跨平台分配的 int 或 uint ?
所以我们有一些 类似的函数this:
void SendData (/* what goes here if we can only send to our function C POD types like int, uint etc? */ socket, std::string message)
{
boost::asio::io_service ioserv;
boost::asio::ip::tcp::socket s(ioserv);
s.assign(boost::asio::ip::tcp::v4(), socket);
s.send(boost::asio::buffer(message));
}
我们想从其他一些函数中调用 SendData
,其中包含一些boost::asio::ip::tcp::socket sock
...所以类似:
//...
SendData(/* what goes here? Is there any sock.getInt() */, "message");
//...
那么我对此有什么选择?哪些简单的 C POD 类型可以从 boost::asio::ip::tcp::socket 中获取,并且稍后可以用 .assign
重新解释?
So we have some function like this:
void SendData (/* what goes here if we can only send to our function C POD types like int, uint etc? */ socket, std::string message)
{
boost::asio::io_service ioserv;
boost::asio::ip::tcp::socket s(ioserv);
s.assign(boost::asio::ip::tcp::v4(), socket);
s.send(boost::asio::buffer(message));
}
and from some other function we want to call SendData
having some boost::asio::ip::tcp::socket sock
... so something like:
//...
SendData(/* what goes here? Is there any sock.getInt() */, "message");
//...
So what are my options for this? What simple C POD types can be taken from boost::asio::ip::tcp::socket that could be later reinterpreted with .assign
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

socket::native()
返回传递给socket::assign()
。在 Linux 和 Mac OS X 上这是一个整数,我不知道 Windows 上是否如此。socket::native()
returns the native representation of what was passed tosocket::assign()
. On Linux and Mac OS X this is an integer, I don't know about Windows.