【问题标题】:What is the difference between Non blocking and Asynchronous socket非阻塞和异步套接字有什么区别
【发布时间】:2014-06-24 07:46:17
【问题描述】:

我们使用以下调用设置的非阻塞和异步套接字模式有什么区别。

  1. 案例 1: int sockfd; // create_sock(sockfd);

    // init_sock(sockfd);

    fcntl(sockfd, F_SETFL, O_NONBLOCK);

  2. 案例2:

    int sockfd; // create_sock(sockfd);

    // init_sock(sockfd);

    int on = 1;

    ioctl(sockfd, FIOASYNC, &on);

  3. 案例 3:

    int sockfd;

    // create_sock(sockfd);

    // init_sock(sockfd);

    int on = 1; ioctl(sockfd, FIONBIO, &on)

在上述所有情况下,套接字的行为是什么。

谢谢,

【问题讨论】:

标签: sockets asynchronous nonblocking ioctl fcntl


【解决方案1】:

“非阻塞”表示该函数要么做了某事,要么没有做某事,并返回一个状态,告诉你是什么。

'异步'是指函数调用的操作在函数返回后继续运行,并通过其他方式通知你其完成或失败,例如:可以查询状态的回调或句柄。

【讨论】:

  • 谢谢,您能否解释一下我提到的三种情况下套接字的行为。
  • 情况 1 和 3 是非阻塞的,这是 O_NONBLOCKFIONBIO 的意思,情况 2 是异步的,这是 FIOASYNC 的意思。我不认为你真的需要我告诉你。
猜你喜欢
  • 2011-09-09
  • 2012-01-15
  • 1970-01-01
  • 2013-02-23
  • 1970-01-01
  • 2019-08-02
  • 1970-01-01
  • 1970-01-01
  • 2011-08-19
相关资源
最近更新 更多