来自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的包装器,具有很多功能?如果是重新实现的话,我希望看到很多内核代码。
发布于 2018-08-07 22:20:15
实际上,套接字实现抽象了底层操作系统实现。WinInet和linux套接字都类似于BSD套接字。
“较低级别”应用程序接口将位于asio::ip::basic_socket<...>::read_some和...::write_some处于与BSD级别API相同级别上。
实际上,服务实现依赖于底层调用,抽象出阻塞与解除阻塞IO的(特定于实现的)细节,并等待就绪的套接字(而不需要使用线程)。
通过从服务对象内部使用成员函数(例如,),您仍然可以通过原始套接字句柄使用原生API。
但是,
要小心不要破坏实现不变量。例如,在这样的句柄上调用
::close,或者更改阻塞模式,都会导致虚假的错误和死锁。
https://stackoverflow.com/questions/51718654
复制相似问题