diff --git a/Userland/Libraries/LibCore/TCPServer.cpp b/Userland/Libraries/LibCore/TCPServer.cpp index 97b4d397b0..048196d268 100644 --- a/Userland/Libraries/LibCore/TCPServer.cpp +++ b/Userland/Libraries/LibCore/TCPServer.cpp @@ -64,6 +64,17 @@ bool TCPServer::listen(const IPv4Address& address, u16 port) return true; } +void TCPServer::set_blocking(bool blocking) +{ + int flags = fcntl(m_fd, F_GETFL, 0); + VERIFY(flags >= 0); + if (blocking) + flags = fcntl(m_fd, F_SETFL, flags & ~O_NONBLOCK); + else + flags = fcntl(m_fd, F_SETFL, flags | O_NONBLOCK); + VERIFY(flags == 0); +} + RefPtr TCPServer::accept() { VERIFY(m_listening); diff --git a/Userland/Libraries/LibCore/TCPServer.h b/Userland/Libraries/LibCore/TCPServer.h index b9769fa246..399765394a 100644 --- a/Userland/Libraries/LibCore/TCPServer.h +++ b/Userland/Libraries/LibCore/TCPServer.h @@ -19,6 +19,7 @@ public: bool is_listening() const { return m_listening; } bool listen(const IPv4Address& address, u16 port); + void set_blocking(bool blocking); RefPtr accept();