I have a performance sensitive client and server application with stream POSIX TCP sockets. All communications on the socket are done with non-blocking flag. I am using sendmsg(2)
system call to send a message with multiple buffer and use recv(2)
to pick the buffers individually on the other side of the wire.
sendmsg(2)
can send the message partially and I have no idea how can I tell which portion of the message is not sent so I can send it again. I don't want to send entire message again.
I did a little research and found for example Linux CIFS in this case terminates the connection session and send the entire message again. Reference. That is not really what I want.
For example:
void sys_sendmsg(int fd, struct iovec *iov, size_t length, int flags)
{
struct msghdr msg = (struct msghdr) {
.msg_iov = iov,
.msg_iovlen = length,
};
ssize_t iov_byte_len;
for (i = 0; i < msg.msg_iovlen; ++i) {
iov_byte_len += msg.msg_iov[i].iov_len;
}
ssize_t sent_len;
sent_len = sendmsg(fd, &msg, flags);
if( sent_len > 0 && sent_len < iov_byte_len){
// What should I do here ?
// I don't want to send entire message again
// Which portion of this message is sent ?
// Does it send the iovs sequentially ?
}
}