Reputation: 1215
I want to send massive amount of message objects over UDP of my own definition my_message
:
class my_message
{
private:
// Message header
header_type header;
// Message text
byte * data;
public:
...
}
However, if I send an instance of this class, the header would be sent along side the pointer (not the real data). So, the trivial idea is to copy the header and the data into a buffer before sending them.
As you know, UDP operates on messages not streams, which means there is a 1-to-1 relationship between sendto()
and recvfrom()
. I.e. It is impossible to sendto()
two times and receive data in one recvfrom()
.
My problem: Copying data into a new buffer would decrease the efficiency of my application.
One would think of splitting the send into sending header and sending data. This won't work because UDP messages are not ordered on receiving.
My Question: Is there a way to tell the application to sendto()
the message by reading from two different sources?
Upvotes: 0
Views: 173
Reputation: 18410
sendmsg takes an iov, which allows you to specify data from different locations to be sent into one packet by means of an iov (IO-Vector) structure.
This might be what you are looking for.
Upvotes: 2