summaryrefslogtreecommitdiff
path: root/src/sockutils.cc
blob: 53e3ef0355867117d9f4d07eebe494ac8af49fe4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "common.hh"

#include <fcntl.h>

#include "sockutils.hh"

namespace stuff {

bool make_nonblocking(int sock) {
    int flags = fcntl(sock, F_GETFL, 0);
    if (flags < 0) {
        return false;
    }
    if (!(flags & O_NONBLOCK)) {
        flags |= O_NONBLOCK;
        if (fcntl(sock, F_SETFL, flags) < 0) {
            return false;
        }
    }
    return true;
}

}  // namespace stuff