簡體   English   中英

Asio如何包含基於BSD套接字API的低級套接字接口?

[英]How does Asio include a low-level socket interface based on the BSD socket API?

從Asio文檔中:

The Asio library includes a low-level socket interface based on the BSD socket
API, which is widely implemented and supported by extensive literature. It is
also used as the basis for networking APIs in other languages, like Java. This
low-level interface is designed to support the development of efficient and
scalable applications.

那么Asio庫是否重新實現了低級套接字接口呢? 還是Asio庫套接字接口是具有許多功能的BSD套接字API / Winsock的包裝器? 如果是重新實現的話,我希望看到很多內核代碼。

實際上,套接字實現抽象了底層的OS實現。 WinInet和linux套接字都類似於BSD套接字。

“低級” API將位於asio::ip::basic_socket<...>::read_some...::write_some與BSD級別API處於同一級別上。

實際上,服務實現將中繼到基礎調用,從而抽象出阻塞與釋放IO的(特定於實現的)詳細信息,並等待就緒的套接字(無需使用線程)。

您仍然可以通過在服務對象內部使用native_handle()成員函數,將原始API與原始套接字句柄一起使用(例如https://www.boost.org/doc/libs/1_67_0/doc/html/boost_asio/ reference / basic_socket / native_handle.html )。

但是請注意不要破壞實現不變式。 例如,在這樣的句柄上調用::close ,或更改阻止模式將導致虛假的錯誤和死鎖。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM