Socket send/recv size
Posted on 2006-11-21
I'm sending chunks of from a client to a server. The data is about 230K for each send.
It doesn't seem to send all the data. It sends about half of it. On the receiving, I do a while loop which keeps receiving until the recv function returns a value of 0.
However, on the sending end I'm not sure how to do this. Should I come up with an arbtirary number and keep sending that number of bytes in a loop? I'd think that would segfault, because it would probably access data beyond the end of the buffer I'm sending. So how do you know how many bytes to send each time?
My send function is simple, I just do:
int bytes_sent = send(m_sock, buffer.data, buffer.used_bytes, MSG_NOSIGNAL);
if (bytes_sent == -1) return false;
else return true;
How can I loop this so it sends the all the data?