开发者

Boost::asio::socket how to get int or uint from it that would be crossplatformly assignable back?

开发者 https://www.devze.com 2023-04-13 03:33 出处:网络
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)

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消