Linux Network Programming-complete read/write Functions

Source: Internet
Author: User
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.
QUOTE:

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.