Vault
4.1
|
00001 /* 00002 Copyright c1997-2014 Trygve Isaacson. All rights reserved. 00003 This file is part of the Code Vault version 4.1 00004 http://www.bombaydigital.com/ 00005 License: MIT. See LICENSE.md in the Vault top level directory. 00006 */ 00007 00010 #include "vsocketthread.h" 00011 00012 #include "vlistenerthread.h" 00013 00014 VSocketThread::VSocketThread(const VString& threadBaseName, VSocket* socket, VListenerThread* ownerThread) 00015 : VThread( 00016 VSTRING_FORMAT("%s[%s:%d]", threadBaseName.chars(), (socket == NULL ? "?":socket->getHostIPAddress().chars()), (socket == NULL ? 0:socket->getPortNumber())), 00017 VSTRING_FORMAT("vault.messages.%s.%s", threadBaseName.chars(), (socket == NULL ? "?":(VLogger::getCleansedLoggerName(socket->getHostIPAddress())).chars())), 00018 kDeleteSelfAtEnd, kCreateThreadDetached, (ownerThread == NULL) ? NULL : ownerThread->getManagementInterface()) 00019 , mSocket(socket) 00020 , mOwnerThread(ownerThread) 00021 { 00022 } 00023 00024 VSocketThread::~VSocketThread() { 00025 if (mOwnerThread != NULL) { 00026 // Prevent all exceptions from escaping destructor. 00027 try { 00028 mOwnerThread->socketThreadEnded(this); 00029 } catch (...) {} 00030 } 00031 00032 delete mSocket; // socket will close itself on deletion 00033 } 00034 00035 VSocket* VSocketThread::getSocket() const { 00036 return mSocket; 00037 } 00038 00039 VListenerThread* VSocketThread::getOwnerThread() const { 00040 return mOwnerThread; 00041 } 00042 00043 void VSocketThread::closeAndStop() { 00044 if (mSocket != NULL) { 00045 mSocket->close(); 00046 } 00047 00048 this->stop(); 00049 } 00050