如何重置套接字回成阻塞模式(后我将它设置为非阻塞模式)? [英] How to reset a socket back to blocking mode (after I set it to nonblocking mode)?
本文介绍了如何重置套接字回成阻塞模式(后我将它设置为非阻塞模式)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我看过这对于插座设置为非阻塞模式。
I have read this regarding setting a socket to non-blocking mode.
<一个href=\"http://www.gnu.org/software/libc/manual/html_mono/libc.html#File-Status-Flags\">http://www.gnu.org/software/libc/manual/html_mono/libc.html#File-Status-Flags
下面是我做过什么:
static void setnonblocking(int sock)
{
int opts;
opts = fcntl(sock,F_GETFL);
if (opts < 0) {
perror("fcntl(F_GETFL)");
exit(EXIT_FAILURE);
}
opts = (opts | O_NONBLOCK);
if (fcntl(sock,F_SETFL,opts) < 0) {
perror("fcntl(F_SETFL)");
exit(EXIT_FAILURE);
}
return;
}
如何设置插座回成阻塞模式?我没有看到一个O_BLOCK标志?
How can I set the socket back to Blocking mode? I don't see a O_BLOCK flag?
感谢您。
推荐答案
你尝试清除了O_NONBLOCK标志?
Did you try clearing the O_NONBLOCK flag?
opts = opts & (~O_NONBLOCK)
这篇关于如何重置套接字回成阻塞模式(后我将它设置为非阻塞模式)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文