2、linux中read,write和recv,send的區別

來源:互聯網
上載者:User

1、recv和send函數提供了和read和write差不多的功能。但是他們提供了第四個參數來控制讀寫操作.

int recv(int sockfd,void *buf,int len,int flags)

int send(int sockfd,void *buf,int len,int flags)

    前面的三個參數和read,write相同,第四個參數能夠是0或是以下的組合:

_______________________________________________________________

| MSG_DONTROUTE | 不尋找路由表 |

| MSG_OOB | 接受或發送帶外資料 |

| MSG_PEEK | 查看資料,並不從系統緩衝區移走資料 |

| MSG_WAITALL | 等待任何資料 |

|————————————————————–|

    如果flags為0,則和read,write一樣的操作。

2、在unix中,所有的裝置都可以看成是一個檔案,所以我們可以用read來讀取socket資料。

參考

【1】 http://apps.hi.baidu.com/share/detail/137478

【2】 設定非阻塞

http://www.ajaxstu.com/Cbiancheng/107652.html

【3】 http://blog.163.com/solylee@126/blog/static/17182315720111161368585/

【4】 http://blog.163.com/clevertanglei900@126/blog/static/111352259201122001933162/

【5】 http://topic.csdn.net/u/20090703/20/36925146-0f73-47fe-8a71-45ec245166ba.html

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.