Returned values of Recv, send, read, and write in case of socket blocking or non-blocking

Source: Internet
Author: User
Tags socket blocking

1. What do the returned values of Recv in blocking mode and non-blocking mode mean? Is there a difference? (As far as I know at present, there is no distinction between blocking and non-blocking Recv return values, all of which are <0: error, = 0: Connection closed,> 0 receives the data size, especially: when the returned value is <0 and (errno = eintr | errno = ewouldblock | errno = eagain), the connection is considered normal and continues to be received. Only in blocking mode, the Recv will block receiving data. In non-blocking mode, if there is no data, it will return and will not block reading. Therefore, it needs to be read cyclically ).

2. What do the return values of write in blocking mode and non-blocking mode mean? Is there a difference? (As far as I know, there is no distinction between blocking and non-blocking write return values, all of which are <0: error, = 0: the connection is closed, and> 0: The size of data to be sent, especially: if the returned value is <0 and (errno = eintr | errno = ewouldblock | errno = eagain), the connection is considered normal and the request is sent again. Only in blocking mode, write will block data sending. In non-blocking mode, if data cannot be sent for the moment, it will return and will not block write, so it needs to be sent cyclically ).

3. Read return value in blocking mode <0 & errno! = Eintr & errno! = Ewouldblock & errno! = Eagain, the connection is abnormal and needs to be closed. When the read return value is <0 & (errno = eintr | errno = ewouldblock | errno = eagain), no data exists, you need to continue receiving data. If the returned value is greater than 0, the data will be transferred to the system.
In non-blocking mode, the read return value <0 indicates no data, = 0 indicates that the connection is disconnected, and> 0 indicates that the data is received.
Are the returned values in these two modes explained in detail or accurately?

4. Whether to send the returned value in blocking mode or non-blocking mode <0 & (errno = eintr | errno = ewouldblock | errno = eagain) indicates that the sending fails temporarily, retry. If the return value of send is <= 0, & errno! = Eintr & errno! = Ewouldblock & errno! = Eagain, the connection is abnormal and needs to be closed. If the return value of send is greater than 0, the data is sent? Whether the return value of send is so understood. In blocking mode and non-blocking mode, if the return value of send = 0 is both sending failed, or if the return value of send is temporarily unavailable, Do You Need To resend it?

1. What do the returned values of Recv in blocking mode and non-blocking mode mean? Is there a difference? (As far as I know at present, there is no distinction between blocking and non-blocking Recv return values, all of which are <0: error, = 0: Connection closed,> 0 receives the data size, especially: when the returned value is <0 and (errno = eintr | errno = ewouldblock | errno = eagain), the connection is considered normal and continues to be received. Only in blocking mode, the Recv will block receiving data. In non-blocking mode, if there is no data, it will return and will not block reading. Therefore, it needs to be read cyclically ).

2. What do the return values of write in blocking mode and non-blocking mode mean? Is there a difference? (As far as I know, there is no distinction between blocking and non-blocking write return values, all of which are <0: error, = 0: the connection is closed, and> 0: The size of data to be sent, especially: if the returned value is <0 and (errno = eintr | errno = ewouldblock | errno = eagain), the connection is considered normal and the request is sent again. Only in blocking mode, write will block data sending. In non-blocking mode, if data cannot be sent for the moment, it will return and will not block write, so it needs to be sent cyclically ).

3. Read return value in blocking mode <0 & errno! = Eintr & errno! = Ewouldblock & errno! = Eagain, the connection is abnormal and needs to be closed. When the read return value is <0 & (errno = eintr | errno = ewouldblock | errno = eagain), no data exists, you need to continue receiving data. If the returned value is greater than 0, the data will be transferred to the system.
In non-blocking mode, the read return value <0 indicates no data, = 0 indicates that the connection is disconnected, and> 0 indicates that the data is received.
Are the returned values in these two modes explained in detail or accurately?

4. Whether to send the returned value in blocking mode or non-blocking mode <0 & (errno = eintr | errno = ewouldblock | errno = eagain) indicates that the sending fails temporarily, retry. If the return value of send is <= 0, & errno! = Eintr & errno! = Ewouldblock & errno! = Eagain, the connection is abnormal and needs to be closed. If the return value of send is greater than 0, the data is sent? Whether the return value of send is so understood. In blocking mode and non-blocking mode, if the return value of send = 0 is both sending failed, or if the return value of send is temporarily unavailable, Do You Need To resend it?

5. Many people say that read will block reading in blocking mode. Is that true? My colleagues and I tried to avoid blocking read.

6. I found a lot of information on the network, which is very general. The score is greater than 0, less than 0, and equal to 0. Blocking and non-blocking are not distinguished, and no error number is distinguished, I hope that experts can answer the above questions one by one. The more detailed the problem, the better. Generally, csdn is used less and the score is less. Sorry.

 

Http://topic.csdn.net/u/20090428/13/4fd54186-d70a-4ff7-9b57-4af83f225e90.html

Http://hi.baidu.com/gamedot/blog/item/cb91512bcabf92f3e7cd402f.html

SVN checkout SVN: // 172.16.0.234/home/svnroot/love3/trunk

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.