Boost::asio::socket 如何从中获取可跨平台分配的 int 或 uint ?

发布于 12-10 04:35 字数 809 浏览 4 评论 0原文

所以我们有一些 类似的函数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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

记忆里有你的影子2024-12-17 04:35:36

可以从 boost::asio::ip::tcp::socket 获取哪些简单的 C POD 类型
稍后可以用 assign() 重新解释?

socket::native() 返回传递给 socket::assign()。在 Linux 和 Mac OS X 上这是一个整数,我不知道 Windows 上是否如此。

What simple C POD types can be taken from boost::asio::ip::tcp::socket
that could be later reinterpreted with assign()?

socket::native() returns the native representation of what was passed to socket::assign(). On Linux and Mac OS X this is an integer, I don't know about Windows.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文