PDA

View Full Version : recvall function in C


Materialised
05-04-2004, 01:34 PM
Hi,

Does anyone have a recvall() function in C to correspond with the
sendall() function I define below?

int
sendall(int s, char *buf, int *len)
{
int total = 0;
//how many bytes we have sent
int bytesleft = *len;
//how many we have left to send
int n;

while (total < *len) {
n = send(s, buf + total, bytesleft, 0);
if (n == -1) {
break;
}
total += n;
bytesleft -= n;
}
*len = total;
//return number actually sent here
return n == -1 ? -1 : 0;
//return -1 on failure, 0 on success
}
--
------
Materialised

perl -e 'printf "%silto%c%sck%ccodegurus%corg%c", "ma", 58, "mi", 64,
46, 10;'

Paul E. Black
05-05-2004, 08:18 AM
Materialised <Materialised@privacy.net> writes:
Does anyone have a recvall() function in C to correspond with the sendall() function I define below? int sendall(int s, char *buf, int *len) { int total = 0; //how many bytes we have sent int bytesleft = *len; //how many we have left to send int n; while (total < *len) { n = send(s, buf + total, bytesleft, 0); if (n == -1) { break; } total += n; bytesleft -= n; } *len = total; //return number actually sent here return n == -1 ? -1 : 0; //return -1 on failure, 0 on success }

If the length is 0 (*len is null initially), n is undefined.

How would a recvall() know when the transmission is done?

-paul-
--
Paul E. Black (p.black@acm.org)


MyLounge.com Site Map
Forum: Cars, Cell Phone, Database, Games, Home Improvement, IT, Music, School, Sports, Web Design, Web Server, Weight Loss

The MyLounge.com forum is intended for informational use only and should not be relied upon and is not a substitute for any advice. The information contained on MyLounge.com are opinions and suggestions of members and is not a representation of the opinions of MyLounge.com. MyLounge.com does not warrant or vouch for the accuracy, completeness or usefulness of any postings or the qualifications of any person responding. Please consult a expert or seek the services of an attorney in your area for more accuracy on your specific situation. Please note that our forums also serve as mirrors to Usenet newsgroups. Many posts you see on our forums are made by newsgroup users who may not be members of MyLounge.com Term of Service