Does sendmsg
free memory of the buffer or msg?
Please guide me on this.
Does sendmsg
free memory of the buffer or msg?
Please guide me on this.
No, sendmsg()
does not free the passed-in memory. It cannot possibly do so, because that memory may not even have come from malloc()
. You can free()
the memory any time after calling sendmsg()
, as the system will have already made the necessary copies.
No you cannot do free it. It just sends out bytes of memory making using of msghdr
structure.
Usually you allocate memory write into iovec of msghdr
and call sendmsg to transfer it as,
char buffer[SIZE]="DATA"; // Data to send into buffer
struct iovec io; // Segment which will store outgoing message
struct msghdr msgh; // msghdr structure
...
io.iov_base = buffer; // Specify the components of the message in an iovec
io.iov_len = SIZE;
msgh.msg_iov = &io;
...
sendmsg(fd,&msgh,0); // send msg which just send msg in a iovec buffer