Search code examples
c++socketsboostbufferbsd

Boost::asio to Struct (like recv)


i wanted to ask, if there is a possibility to receive from boost::asio::ip::udp::socket the data directly into a struct like in standard BSD Sockets:

    struct T;
    size = recv(sock,&T,sizeof(T));

Since i receive a lot of fixed size data,, i really do not want to copy the data into a buffer first and from there into a struct. If this is not easy achievable i will stick to standard BSD sockets again. The Struct is serializable, and that problem should not be a Concern at this moment.


Solution

  • Reading the documentation:

    socket.receive(boost::asio::buffer((void *)&T, sizeof(T)));