tags:

views:

120

answers:

2

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

http://www.ia.pw.edu.pl/~wujek/dokumentacja/gnu/libc/libc_8.html#SEC141

Here is what I did:

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;
}

How can I set the socket back to Blocking mode? I don't see a O_BLOCK flag?

Thank you.

+2  A: 

Did you try clearing the O_NONBLOCK flag?

opts = opts & (~O_NONBLOCK)
Moron
A: 

Alternative way to clear the flag:

opts ^= O_NONBLOCK;
eswald