Codebase list i3-gaps / 277d436 libi3 / nonblock.c
277d436

Tree @277d436 (Download .tar.gz)

nonblock.c @277d436raw · history · blame

#include "libi3.h"

#include <err.h>
#include <fcntl.h>

/*
 * Puts the given socket file descriptor into non-blocking mode or dies if
 * setting O_NONBLOCK failed. Non-blocking sockets are a good idea for our
 * IPC model because we should by no means block the window manager.
 *
 */
void set_nonblock(int sockfd) {
    int flags = fcntl(sockfd, F_GETFL, 0);
    if (flags & O_NONBLOCK) {
        return;
    }
    flags |= O_NONBLOCK;
    if (fcntl(sockfd, F_SETFL, flags) < 0) {
        err(-1, "Could not set O_NONBLOCK");
    }
}