国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 操作系統(tǒng) > 正文

非阻塞I/O 復(fù)用-conncet

2024-06-28 13:26:39
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
非阻塞I/O 復(fù)用-conncet

When a TCP socket is set to nonblocking and then connect is called, connect returns immediately with an error of EINPROGRESS but the TCP three-way handshake continues. We then check for either a successful or unsuccessful completion of the connection's establishment using select. There are three uses for a nonblocking connect:

  1. We can overlap other processing with the three-way handshake. A connect takes one RTT to complete (Section 2.6) and this can be anywhere from a few milliseconds on a LAN to hundreds of milliseconds or a few seconds on a WAN. There might be other processing we wish to perform during this time.

  2. We can establish multiple connections at the same time using this technique. This has become popular with Web browsers, and we will show an example of this in Section 16.5.

  3. Since we wait for the connection to be established using select, we can specify a time limit for select, allowing us to shorten the timeout for the connect. Many implementations have a timeout for connect that is between 75 seconds and several minutes. There are times when an application wants a shorter timeout, and using a nonblocking connect is one way to accomplish this. Section 14.2 talks about other ways to place timeouts on socket Operations.

As simple as the nonblocking connect sounds, there are other details we must handle:

  • Even though the socket is nonblocking, if the server to which we are connecting is on the same host, the connection is normally established immediately when we call connect. We must handle this scenario.

  • Berkeley-derived implementations (and POSIX) have the following two rules regarding select and nonblocking connects:

  1. When the connection completes successfully, the descriptor becomes writable (p. 531 of TCPv2).

  2. When the connection establishment encounters an error, the descriptor becomes both readable and writable (p. 530 of TCPv2).

    These two rules regarding select fall out from our rules in Section 6.3 about the conditions that make a descriptor ready. A TCP socket is writable if there is available space in the send buffer (which will always be the case for a connecting socket since we have not yet written anything to the socket) and the socket is connected (which occurs only when the three-way handshake completes). A pending error causes a socket to be both readable and writable.

There are many portability problems with nonblocking connects that we mention in the examples that follow.

非阻塞connect的三種用法:

1、 三次握手過(guò)程可以和其他操作重疊進(jìn)行。

2、 可以同時(shí)建立多個(gè)連接。這種做法在瀏覽器中很常見(jiàn)。

3、可以利用select來(lái)縮短connect的等待時(shí)間。各種版本的select超時(shí)時(shí)間從75s到幾分鐘。

其他需要考慮的細(xì)節(jié):

如果復(fù)位端和客戶端在一個(gè)主機(jī)上,connect函數(shù)可能立即返回(三次握手已經(jīng)完成),必須考慮這種場(chǎng)景。

Berkeley-derived和POSIX系統(tǒng)處理select和非阻塞connect時(shí)有如下規(guī)則:

1. 連接成功建立時(shí),描述符變?yōu)榭蓪?xiě);

2. 連接過(guò)程出現(xiàn)錯(cuò)誤時(shí),描述符變?yōu)榭勺x可寫(xiě)。


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 西充县| 吉安市| 贺兰县| 探索| 化德县| 磐安县| 贞丰县| 德阳市| 康平县| 平凉市| 辰溪县| 秭归县| 连山| 安义县| 桂平市| 固原市| 澳门| 金坛市| 泰来县| 宽城| 集安市| 温州市| 喀喇沁旗| 太和县| 芜湖县| 海原县| 滕州市| 建宁县| 庄浪县| 衡阳县| 遂川县| 平南县| 汉中市| 句容市| 筠连县| 湟源县| 江达县| 武定县| 富顺县| 张家界市| 青阳县|