aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2020-11-16 10:14:19 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2020-11-16 10:14:19 +0100
commita21eb76abe2ccee43ae2bae1eddcc7b2bd9420f8 (patch)
tree870991f42bceb64966f984528441c7d7839bef67 /src
parent6a15896c7c5b8375b51e4eb370f1f57587ab7e3c (diff)
downloadODR-AudioEnc-a21eb76abe2ccee43ae2bae1eddcc7b2bd9420f8.tar.gz
ODR-AudioEnc-a21eb76abe2ccee43ae2bae1eddcc7b2bd9420f8.tar.bz2
ODR-AudioEnc-a21eb76abe2ccee43ae2bae1eddcc7b2bd9420f8.zip
Replace non-portable SOCK_NONBLOCK by fcntl O_NONBLOCK
Diffstat (limited to 'src')
-rw-r--r--src/PadInterface.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/PadInterface.cpp b/src/PadInterface.cpp
index 7e8a6ee..e9285d8 100644
--- a/src/PadInterface.cpp
+++ b/src/PadInterface.cpp
@@ -25,6 +25,7 @@
#include <cassert>
#include <sys/socket.h>
#include <sys/un.h>
+#include <fcntl.h>
#include <unistd.h>
#define MESSAGE_REQUEST 1
@@ -32,15 +33,26 @@
using namespace std;
-void PadInterface::open(const std::string &pad_ident)
+void PadInterface::open(const std::string& pad_ident)
{
m_pad_ident = pad_ident;
- m_sock = socket(AF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0);
+ m_sock = socket(AF_UNIX, SOCK_DGRAM, 0);
if (m_sock == -1) {
throw runtime_error("PAD socket creation failed: " + string(strerror(errno)));
}
+ int flags = fcntl(m_sock, F_GETFL);
+ if (flags == -1) {
+ std::string errstr(strerror(errno));
+ throw std::runtime_error("TCP: Could not get socket flags: " + errstr);
+ }
+
+ if (fcntl(m_sock, F_SETFL, flags | O_NONBLOCK) == -1) {
+ std::string errstr(strerror(errno));
+ throw std::runtime_error("TCP: Could not set O_NONBLOCK: " + errstr);
+ }
+
struct sockaddr_un claddr;
memset(&claddr, 0, sizeof(struct sockaddr_un));
claddr.sun_family = AF_UNIX;