Read and Write Functions of Linux-C

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.