aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Chemeris <Alexander.Chemeris@gmail.com>2013-07-14 02:00:00 +0400
committerAlexander Chemeris <Alexander.Chemeris@gmail.com>2013-07-14 23:11:54 +0400
commitd4a8c1360e5d54188b648766dde199fa37f2ed27 (patch)
treedbde31e30f6ea0cb8fcf22109600fbf5cb0b32f4
parent69b6a6dfcd882df180e9d5e9856225f4b1d2eeed (diff)
CommonLibs: Add shutdown() method to the DatagramSocket class.
This method is useful to abort a blocking operations on a socket during shutdown.
-rw-r--r--CommonLibs/Sockets.cpp6
-rw-r--r--CommonLibs/Sockets.h6
2 files changed, 12 insertions, 0 deletions
diff --git a/CommonLibs/Sockets.cpp b/CommonLibs/Sockets.cpp
index dd7527c..5af82ef 100644
--- a/CommonLibs/Sockets.cpp
+++ b/CommonLibs/Sockets.cpp
@@ -1,5 +1,6 @@
/*
* Copyright 2008, 2010 Free Software Foundation, Inc.
+* Copyright 2013 Alexander Chemeris <Alexander.Chemeris@fairwaves.ru>
*
*
* This software is distributed under the terms of the GNU Affero Public License.
@@ -129,6 +130,11 @@ void DatagramSocket::close()
::close(mSocketFD);
}
+void DatagramSocket::shutdown()
+{
+ ::shutdown(mSocketFD, SHUT_RDWR);
+}
+
DatagramSocket::~DatagramSocket()
{
diff --git a/CommonLibs/Sockets.h b/CommonLibs/Sockets.h
index c79f79a..b5219c6 100644
--- a/CommonLibs/Sockets.h
+++ b/CommonLibs/Sockets.h
@@ -1,5 +1,6 @@
/*
* Copyright 2008, 2010 Free Software Foundation, Inc.
+* Copyright 2013 Alexander Chemeris <Alexander.Chemeris@fairwaves.ru>
*
* This software is distributed under the terms of the GNU Affero Public License.
* See the COPYING file in the main directory for details.
@@ -134,6 +135,11 @@ public:
/** Close the socket. */
void close();
+ /** Shutdown the socket without destroying the descriptor
+ * Use this to interrupt blocking read()
+ */
+ void shutdown();
+
};