Linux Network Programming-complete read/write functions-general Linux technology-Linux programming and kernel information. The following is a detailed description. ? Once we establish a connection, our next step is to communicate. in Linux, We will regard the channel we have established as a file descriptor. In this way, when the Server communicates with the client, everything needs to be read and written to the file descriptor. just like reading and writing to a file.
4.1 write a function
Ssize_t write (int fd, const void * buf, size_t nbytes)
The write function writes the nbytes bytes in the buf to the file descriptor fd. the number of bytes written when the operation succeeds. -1. set the errno variable. in network programs, there are two possibilities when we write to the socket file descriptor.
1) the return value of write is greater than 0, indicating that some or all data is written.
2) If the returned value is less than 0, an error occurs. We need to handle the error based on the error type.
If the error is EINTR, an interruption error occurs during write.
If it is EPIPE, the network connection is faulty (the other party has closed the connection ).
To handle the above situations, we compile a write function to handle these situations.