Home > Back-end >  Socket the function of the write (fd, (text written), len - written) how to understand
Socket the function of the write (fd, (text written), len - written) how to understand

Time:09-27

Write_to_socket (int fd, char * text, size_t len)
{
Ssize_t retval;
Size_t written;

Written=0;
While (written & lt; Len)
{
Retval=write (fd (text + written), len - written);
If (retval==1)
{
The debug (LOG_CRIT, "Failed to write client data to the child: % s", the strerror (errno));
return 0;
}
The else
{
Written +=retval;
}
}
return 1;
}

CodePudding user response:

Not a one-time to len length data write to
So every time after the write write successful length, determine whether complete
Skip unfinished before successful data, will continue to write the remaining,

CodePudding user response:

Text is a pointer to a char * string, text + written is equal to the pointer offset written characters, the equivalent of & amp; Text [written],
Len - written transfer the rest of the such a long string,
  • Related