there is a function to send some bytes over the socket
static int sendall(rrd_client_t *client,const char *msg,
size_t len, int allow_retry)
{
int ret = 0;
char *bufp = (char *) msg;
if (client == NULL)
return -1;
while (ret != -1 && len > 0) {
ret = send(client->sd, msg, len, 0);
if (ret > 0) {
bufp += ret;
len -= ret;
}
}
if ((ret < 0) && allow_retry) {
/* Try to reconnect and start over.
* Don't further allow retries to avoid endless loops. */
if (reconnect(client) == 0)
return sendall(client, msg, len, 0);
}
return ret;
}
at line where send function is called shouldn't it be bufp instead of msg ?
Let me know your comments. I think they did it like that because send could actually send less bytes and still return success, so they made it send the rest of the bytes, but it sends all the bytes all over again.
I take you to mean the call to
send()in this loop:Yes, there,
send()should be called asThe intent is to ensure that all of the the requested data are sent, in light of the fact that
send()can perform partial transfers. With the corrected code, if a successful partial transfer occurs then the program just loops back to continue sending where the firstsend()left off, as many times as necessary.On the other hand, the erroneous code restarts from the beginning in the event of a partial transfer. Unless the remote peer is ready for that and has a way to detect and correct for it, that will produce data corruption whenever it occurs. Probably such events are rare, which could explain why the bug persists.