Read Function
Ssize_t read (int fd, void * Buf, size_t nbyte)
The READ function is responsible
When FD reads the content to Buf, the read operation returns the actual number of bytes read. If the returned value is 0, the read operation has ended.
If the value is less than 0, an error occurs. if the error is
Eintr indicates that the read operation is interrupted. If econnrest is used, the network connection is faulty.
Write function
Ssize_t
Write (int fd, const void * Buf, size_t nbytes)
The Write function writes the nbytes bytes in the Buf.
Input file descriptor FD. The number of written bytes is returned when the file descriptor FD is successful.-1 is returned when the file fails, and the errno variable is set.ProgramWhen we write to the socket file descriptor, there are two possibilities.
1) Write
The return value 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 ).
3) nbytes
It can be larger than the actual write size. For example, the buffer can only write 100, but write 1000. The first 100 words are successfully written. This feature can be used with repeated write operations by moving pointers.