diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2020-11-16 10:14:12 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2020-11-16 10:14:12 +0100 |
commit | 94871e57988f96881405e02e1f628946fed3651c (patch) | |
tree | d43c32c7acfb5595f7326287643d5baedb725eeb /src | |
parent | 1f812a495b750b40fabecddea6c920ddf1ff0e37 (diff) | |
download | ODR-SourceCompanion-94871e57988f96881405e02e1f628946fed3651c.tar.gz ODR-SourceCompanion-94871e57988f96881405e02e1f628946fed3651c.tar.bz2 ODR-SourceCompanion-94871e57988f96881405e02e1f628946fed3651c.zip |
Replace non-portable SOCK_NONBLOCK by fcntl O_NONBLOCK
Diffstat (limited to 'src')
-rw-r--r-- | src/PadInterface.cpp | 16 |
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; |