diff --git a/Libraries/LibCore/CLocalSocket.cpp b/Libraries/LibCore/CLocalSocket.cpp index 20837a066f9..00d96c4c132 100644 --- a/Libraries/LibCore/CLocalSocket.cpp +++ b/Libraries/LibCore/CLocalSocket.cpp @@ -4,7 +4,7 @@ CLocalSocket::CLocalSocket(CObject* parent) : CSocket(CSocket::Type::Local, parent) { - int fd = socket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0); + int fd = socket(AF_LOCAL, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); if (fd < 0) { set_error(fd); } else { diff --git a/Libraries/LibCore/CSocket.cpp b/Libraries/LibCore/CSocket.cpp index 1768fa6255f..ee334bdf59d 100644 --- a/Libraries/LibCore/CSocket.cpp +++ b/Libraries/LibCore/CSocket.cpp @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include CSocket::CSocket(Type type, CObject* parent) @@ -31,6 +33,17 @@ bool CSocket::connect(const String& hostname, int port) return connect(host_address, port); } +void CSocket::set_blocking(bool blocking) +{ + int flags = fcntl(fd(), F_GETFL, 0); + ASSERT(flags >= 0); + if (blocking) + flags = fcntl(fd(), F_SETFL, flags | O_NONBLOCK); + else + flags = fcntl(fd(), F_SETFL, flags & O_NONBLOCK); + ASSERT(flags >= 0); +} + bool CSocket::connect(const CSocketAddress& address, int port) { ASSERT(!is_connected()); diff --git a/Libraries/LibCore/CSocket.h b/Libraries/LibCore/CSocket.h index 8521bb02f98..28702306d3b 100644 --- a/Libraries/LibCore/CSocket.h +++ b/Libraries/LibCore/CSocket.h @@ -23,6 +23,7 @@ public: bool send(const ByteBuffer&); bool is_connected() const { return m_connected; } + void set_blocking(bool blocking); CSocketAddress source_address() const { return m_source_address; } int source_port() const { return m_source_port; }