什么是异步套接字? [英] What are Async Sockets?

查看:596
本文介绍了什么是异步套接字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是异步套接字?他们如何从普通插座不同(阻塞和非阻塞)?

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:


  1. 打开定期插座,但不从中读取(因为阅读()块),直到你知道有一些东西被读取。您可以使用选择()调查()来检查是否有数据接口(S)读取,如果有什么东西,读它,因为阅读()不会阻止。

  1. Open regular socket, but do not read from it (because read() blocks) until you know there it something to be read. You can use select() or poll() to check whether there are data to read from socket(s), and if there is something, read it, as read() 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆