0

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?

Community
  • 1
  • 1
Rella
  • 65,003
  • 109
  • 363
  • 636
  • The contents of the buffer are not translated on the wire, so sending an `int` from one machine to another can be read directly in if the platforms are compatible. If they are not, then the receiving device will need to translate the byte ordering. – Chad Oct 16 '11 at 14:03
  • 1
    Uh, why not `socket*` (or `void*` then casted to `socket*`)? – ildjarn Oct 16 '11 at 18:04

1 Answers1

-1

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.

Sam Miller
  • 23,808
  • 4
  • 67
  • 87