如何将套接字重置回阻塞模式(在我将其设置为非阻塞模式之后)?

如何将套接字重置回阻塞模式(在我将其设置为非阻塞模式之后)?

问题描述:

我已阅读有关将套接字设置为非阻塞模式的内容.

I have read this regarding setting a socket to non-blocking mode.

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)