linux socket API / listen() 两个队列以及第 2 个参数的作用
生活随笔
收集整理的這篇文章主要介紹了
linux socket API / listen() 两个队列以及第 2 个参数的作用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、SYN 隊列,當 Server 接收到 SYN 時,就將該 socket 放入了 SYN 隊列中,即:未完成連接隊列。
2、Accept 隊列,當 Server 發送完 SYN + ACK 之后,Client 回復了 ACK,則內核將該 socket 從 SYN 隊列遷移到 Accept 隊列中,即:已完成連接隊列。
3、第 2 個參數的作用
man listen,得到的答案如下:
The backlog argument defines the maximum length to which the queue of pending connections for sockfd may grow. If a connection request arrives when the queue is full, the client may receive an error with an indication of ECONNREFUSED or, if the underlying protocol supports retransmission, the request may be ignored so that a later reattempt at connec‐ tion succeeds.說明 backlog 的含義是 SYN 隊列的長度。?
拓展:
? ? ? ?對于 accept() 函數來說,其就是不斷監聽 Accept 隊列中是否為空。若為空則繼續堵塞,若有 socket ,則取出 socket 描述符的值、Client 的 IP、Port 和協議族這些信息并返回。
?
(SAW:Game Over!)
總結
以上是生活随笔為你收集整理的linux socket API / listen() 两个队列以及第 2 个参数的作用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: TCPIP / MTU 和 MSS 的区
- 下一篇: 数据结构与算法 / B- Tree 和