Added some performance logging capabilities and socket cleanup for new broadcast thread sockets

This commit is contained in:
Mark Vejvoda
2010-04-15 01:19:00 +00:00
parent 86f0b8adb0
commit 30c4eb2b96
12 changed files with 108 additions and 38 deletions

View File

@@ -120,7 +120,8 @@ public:
static string getHostName();
static string getIp();
bool isSocketValid(PLATFORM_SOCKET *validateSocket=NULL) const;
bool isSocketValid() const;
static bool isSocketValid(const PLATFORM_SOCKET *validateSocket);
protected:
static void throwException(string str);

View File

@@ -34,11 +34,13 @@ public:
enum DebugType {
debugSystem,
debugNetwork
debugNetwork,
debugPerformance
};
static bool enableDebugText;
static bool enableNetworkDebugInfo;
static bool enablePerformanceDebugInfo;
static const char *debugLogFile;
static void OutputDebug(DebugType type, const char *fmt, ...);

View File

@@ -650,17 +650,21 @@ std::vector<std::string> Socket::getLocalIPAddressList() {
return ipList;
}
bool Socket::isSocketValid(PLATFORM_SOCKET *validateSocket) const {
bool Socket::isSocketValid() const {
return Socket::isSocketValid(&sock);
}
bool Socket::isSocketValid(const PLATFORM_SOCKET *validateSocket) {
#ifdef WIN32
if(validateSocket == NULL) {
return (sock != INVALID_SOCKET);
return false;
}
else {
return (*validateSocket != INVALID_SOCKET);
}
#else
if(validateSocket == NULL) {
return (sock > 0);
return false;
}
else {
return (*validateSocket > 0);
@@ -726,7 +730,7 @@ bool Socket::hasDataToRead(std::map<PLATFORM_SOCKET,bool> &socketTriggeredList)
itermap != socketTriggeredList.end(); itermap++)
{
PLATFORM_SOCKET socket = itermap->first;
if(socket > 0)
if(Socket::isSocketValid(&socket) == true)
{
FD_SET(socket, &rfds);
imaxsocket = max(socket,imaxsocket);
@@ -784,7 +788,7 @@ bool Socket::hasDataToRead(PLATFORM_SOCKET socket)
{
bool bResult = false;
if(socket > 0)
if(Socket::isSocketValid(&socket) == true)
{
fd_set rfds;
struct timeval tv;
@@ -1452,6 +1456,15 @@ void BroadCastClientSocketThread::execute() {
setRunningStatus(false);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Broadcast Client thread is exiting\n");
}
#ifndef WIN32
::close(bcfd);
bcfd = INVALID_SOCKET;
#else
::closesocket(bcfd);
bcfd = -1;
#endif
}
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@@ -1725,7 +1738,7 @@ void BroadCastSocketThread::execute() {
for( pn = 1; ; pn++ )
{
for(unsigned int idx = 0; idx < ipList.size() && idx < MAX_NIC_COUNT; idx++) {
if( bcfd[idx] > 0 ) {
if( Socket::isSocketValid(&bcfd[idx]) == true ) {
try {
// Send this machine's host name and address in hostname:n.n.n.n format
sprintf(buff,"%s",myhostname);
@@ -1779,6 +1792,18 @@ void BroadCastSocketThread::execute() {
}
}
for(unsigned int idx = 0; idx < ipList.size() && idx < MAX_NIC_COUNT; idx++) {
if( Socket::isSocketValid(&bcfd[idx]) == true ) {
#ifndef WIN32
::close(bcfd[idx]);
bcfd[idx] = INVALID_SOCKET;
#else
::closesocket(bcfd[idx]);
bcfd[idx] = -1;
#endif
}
}
setRunningStatus(false);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Broadcast thread is exiting\n");

View File

@@ -35,12 +35,14 @@ using namespace Shared::Platform;
namespace Shared{ namespace Util{
bool SystemFlags::enableDebugText = false;
bool SystemFlags::enableNetworkDebugInfo = false;
const char * SystemFlags::debugLogFile = NULL;
bool SystemFlags::enableDebugText = false;
bool SystemFlags::enableNetworkDebugInfo = false;
bool SystemFlags::enablePerformanceDebugInfo = false;
const char * SystemFlags::debugLogFile = NULL;
ofstream SystemFlags::fileStream;
int SystemFlags::lockFile = -1;
string SystemFlags::lockfilename = "";
int SystemFlags::lockFile = -1;
string SystemFlags::lockfilename = "";
inline bool acquire_file_lock(int hnd)
{
@@ -82,8 +84,9 @@ void SystemFlags::Close() {
}
void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) {
if((type == debugSystem && SystemFlags::enableDebugText == false) ||
(type == debugNetwork && SystemFlags::enableNetworkDebugInfo == false)) {
if((type == debugSystem && SystemFlags::enableDebugText == false) ||
(type == debugNetwork && SystemFlags::enableNetworkDebugInfo == false ||
type == debugPerformance && SystemFlags::enablePerformanceDebugInfo == false)) {
return;
}