Code: Select all
BOOL sendbuf (int socket, char *buf, int len)
{
int sent;
while (len > 0)
{
sent = send (socket, buf, len, 0 /* flags */);
if (sent == -1)
return (FALSE);
len = len - sent;
buf = buf + sent;
}
return (TRUE);
}Code: Select all
function sendbuf ($socket, $buffer, $len)
{
while ($len > 0)
{
$sent = fwrite ($socket, $buffer, $len);
//error checking omitted for clairty
$len = $len - $sent;
$buffer = substr ($buffer, $sent); //this is a really bad way to skip over transmitted bytes
}
}Can anyone suggest a more efficient way to "advance" in a string and use it as a parameter to fwrite ?