move set_nonblock, create_socket and path_exists to libi3
This commit is contained in:
committed by
Michael Stapelberg
parent
e4f12ac349
commit
131a6158c8
20
libi3/nonblock.c
Normal file
20
libi3/nonblock.c
Normal file
@ -0,0 +1,20 @@
|
||||
#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");
|
||||
}
|
Reference in New Issue
Block a user