diff --git a/lib/socket.cpp b/lib/socket.cpp index 34647692..703aed67 100644 --- a/lib/socket.cpp +++ b/lib/socket.cpp @@ -855,6 +855,13 @@ Socket::Connection Socket::Server::accept(bool nonblock){ return tmp; } +/// Set this socket to be blocking (true) or nonblocking (false). +void Socket::Server::setBlocking(bool blocking){ + if (sock >= 0){ + setFDBlocking(sock, blocking); + } +} + /// Close connection. The internal socket is closed and then set to -1. /// If the connection is already closed, nothing happens. void Socket::Server::close(){ diff --git a/lib/socket.h b/lib/socket.h index 03aec9c2..227cf018 100644 --- a/lib/socket.h +++ b/lib/socket.h @@ -109,6 +109,7 @@ namespace Socket { Server(int port, std::string hostname = "0.0.0.0", bool nonblock = false); ///< Create a new TCP Server. Server(std::string adres, bool nonblock = false); ///< Create a new Unix Server. Connection accept(bool nonblock = false); ///< Accept any waiting connections. + void setBlocking(bool blocking); ///< Set this socket to be blocking (true) or nonblocking (false). bool connected() const; ///< Returns the connected-state for this socket. void close(); ///< Close connection. int getSocket(); ///< Returns internal socket number.