什么是异步套接字? [英] What are Async Sockets?
问题描述
什么是异步套接字?他们如何从普通插座不同(阻塞和非阻塞)?
What are Async Sockets? How are they different from normal sockets (Blocking and Non-Blocking)?
在这个方向的任何指针或任何教程的链接会有所帮助。
Any pointers in that direction or any links to tutorials will be helpful.
感谢。
推荐答案
有三种方式与异步的方式插口进行通信:
There are three ways to communicate with sockets in async way:
-
打开定期插座,但不从中读取(因为
阅读()
块),直到你知道有一些东西被读取。您可以使用选择()
或调查()
来检查是否有数据接口(S)读取,如果有什么东西,读它,因为阅读()
不会阻止。
Open regular socket, but do not read from it (because
read()
blocks) until you know there it something to be read. You can useselect()
orpoll()
to check whether there are data to read from socket(s), and if there is something, read it, asread()
won't block.
开关插座非阻塞I / O,通过设置 O_NONBLOCK
标记与的fcntl()
功能。在这种情况下阅读()
不会阻止。
Switch socket to non-blocking I/O, by setting O_NONBLOCK
flag with fcntl()
function. In this case read()
won't block.
设置插座的 O_ASYNC
使用标记 FIOASYNC
的选项的ioctl()
(见 7人座
详情)。在这种情况下,当有东西从套接字读取您将收到 SIGIO
信号。
Set socket's O_ASYNC
flag using FIOASYNC
option of ioctl()
(see man 7 socket
for details). In this case you will receive SIGIO
signal when there is something to read from socket.
第三种方法是异步接口。
Third approach is async socket.
这篇关于什么是异步套接字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!