summaryrefslogtreecommitdiff
path: root/cpp/lib/client/Connector.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/lib/client/Connector.cpp')
-rw-r--r--cpp/lib/client/Connector.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/cpp/lib/client/Connector.cpp b/cpp/lib/client/Connector.cpp
index b34e66fd94..c57b3d6dc4 100644
--- a/cpp/lib/client/Connector.cpp
+++ b/cpp/lib/client/Connector.cpp
@@ -57,9 +57,10 @@ void Connector::init(ProtocolInitiation* header){
}
void Connector::close(){
- closed = true;
- socket.close();
- receiver.join();
+ if (markClosed()) {
+ socket.close();
+ receiver.join();
+ }
}
void Connector::setInputHandler(InputHandler* handler){
@@ -101,14 +102,24 @@ void Connector::writeToSocket(char* data, size_t available){
}
void Connector::handleClosed(){
- closed = true;
- socket.close();
- if(shutdownHandler) shutdownHandler->shutdown();
+ if (markClosed()) {
+ socket.close();
+ if(shutdownHandler) shutdownHandler->shutdown();
+ }
+}
+
+bool Connector::markClosed(){
+ if (closed) {
+ return false;
+ } else {
+ closed = true;
+ return true;
+ }
}
void Connector::checkIdle(ssize_t status){
if(timeoutHandler){
- Time t = now() * TIME_MSEC;
+ Time t = now() * TIME_MSEC;
if(status == Socket::SOCKET_TIMEOUT) {
if(idleIn && (t - lastIn > idleIn)){
timeoutHandler->idleIn();