| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 733 人关注过本帖
标题:非阻塞 I/O 笔记
只看楼主 加入收藏
madfrogme
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:21
帖 子:1160
专家分:1106
注 册:2009-6-24
结帖率:98.63%
收藏
 问题点数:0 回复次数:1 
非阻塞 I/O 笔记
By default, sockets are blocking.  We can divide the socket calls that may block into four categories.
1. Input operations-- read(), readv(), recv(), recvfrom(), recvmsg().

If we want to wait until some fixed amount of data is available, we can call our own function readn() or specify the MSG_WAITALL flag

With a nonblocking socket, if the input operation can not be satisfied, we see an immediate return with an error of  EWOULDBLOCK

2. Output operations-- write(), writev(), send(), sendto(), sendmsg().

If there is no room in the socket send buffer for a blocking socket, the process is put to sleep until there is room. With a nonblocking TCP socket, if there is no room at all in the socket send buffer, we return immediately with an error of EWOULDBLOCK.

If there is some room in the socket send buffer, the return value will be the number of bytes the kernel was able to copy into the buffer(short count)

There is no actual UDP socket send buffer. The kernel just copies the application data and moves it down the stack, prepending the UDP and IP headers.

3. Accepting incoming connections-- accept().

If accept() is called for a blocking socket and a new connection is not available,  the process is put to sleep.

4. Initiating outgoing connections -- connect() for TCP

connect() can be used with UDP, but it does not cause a "real" connection to be established; it just causes the kernel to store the peer's IP address and port number.

The connect() function does not return until the client receives the ACK of its SYN. This measn that a TCP connect always blocks the calling process for at least the RTT to the server.

If connect() is called for a nonblocking TCP socket and the connection cannot be established immediately, the erro EINPROGRESS is returned


[ 本帖最后由 madfrogme 于 2012-9-1 21:31 编辑 ]
搜索更多相关主题的帖子: 幸福 into available operation function 
2012-09-01 17:41
爱飞sky
Rank: 2
等 级:论坛游民
威 望:1
帖 子:10
专家分:25
注 册:2012-9-5
收藏
得分:0 
只是其中一部风吧?? 有没有basic idea
2013-12-29 11:19
快速回复:非阻塞 I/O 笔记
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.042371 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved