From 94871e57988f96881405e02e1f628946fed3651c Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Mon, 16 Nov 2020 10:14:12 +0100 Subject: Replace non-portable SOCK_NONBLOCK by fcntl O_NONBLOCK --- src/PadInterface.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src') 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 #include #include +#include #include #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; -- cgit v1.2.3