summaryrefslogtreecommitdiff
path: root/src/sockutils.cc
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@yahoo.com>2015-06-08 22:54:54 +0200
committerJoel Klinghed <the_jk@yahoo.com>2015-06-08 22:54:54 +0200
commit913cfd1c7ef7a145036a8416d4ea815cb5cdb601 (patch)
treef98a19bf120498db7f1f7a193d69655c2644f4fe /src/sockutils.cc
parenta2f209d2f21282d8ddb6ab76d9b6bd8f5f23b37c (diff)
Create sockutils
Diffstat (limited to 'src/sockutils.cc')
-rw-r--r--src/sockutils.cc23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/sockutils.cc b/src/sockutils.cc
new file mode 100644
index 0000000..53e3ef0
--- /dev/null
+++ b/src/sockutils.cc
@@ -0,0 +1,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