From 318d0609dd897d1d444b937da716c562d05f22bb Mon Sep 17 00:00:00 2001 From: Evgeny Gagua Date: Thu, 12 Mar 2026 02:25:49 +0200 Subject: [PATCH] Fixed some Resources Handling in Hardware Manager --- lib/App/common/SQLite_dataBinder.cpp | 88 +++++++++++++++++++- lib/App/common/SQLite_dataBinder.h | 4 +- lib/App/common/deviceNodeCamera.cpp | 6 +- lib/App/common/kernelEventFilterBubble.cpp | 9 +- lib/App/common/kernelModuleEmbedVideo.h | 2 +- lib/App/common/kernelPrototype.cpp | 8 +- lib/App/common/targetPipeLine.cpp | 17 ++-- lib/App/mojo/mojoKernel.cpp | 51 ++++++++++-- lib/App/mojo/mojoRemoteClient.cpp | 6 +- lib/data/net/clientPort.cpp | 95 +++++++++++++++++++--- 10 files changed, 249 insertions(+), 37 deletions(-) diff --git a/lib/App/common/SQLite_dataBinder.cpp b/lib/App/common/SQLite_dataBinder.cpp index 4b15cd01..f2f54b83 100644 --- a/lib/App/common/SQLite_dataBinder.cpp +++ b/lib/App/common/SQLite_dataBinder.cpp @@ -2769,6 +2769,61 @@ uint32_t sqliteDBC::getNIF_IDbyDevice( CSTR device ){ return tVal; }; +DBC_NETWORK_DATA *sqliteDBC::getNetworkData( uint32_t net_id ){ + DBC_NETWORK_DATA *tVal = NULL; + if( m_bStoIsConnected ){ + char tQBuf[CTEXT]; + AAssoc *result; + sprintf(tQBuf, "SELECT * FROM `networks` WHERE `id`=%d", net_id ); +#ifdef DEBUG + LOG(tQBuf); +#endif + result = m_pDataStorage->Query( tQBuf ); + if( result!= NULL ) { + if( result->size() > 0 ) { + tVal = (DBC_NETWORK_DATA *) malloc( sizeof(DBC_NETWORK_DATA)); + if ( tVal ) { + Assoc *cArr; + Assoc::iterator it; + memset( tVal, 0 , sizeof( DBC_NETWORK_DATA )); + tVal->id = net_id; + cArr = result->at(0); + it = cArr->find("nif_id"); + if( it != cArr->end() ){ + tVal->nif_id = atoi(it->second.c_str()); + }; + it = cArr->find("type"); + if( it != cArr->end() ){ + tVal->type = (NETWORK_TYPE) atoi(it->second.c_str()); + }; + it = cArr->find("address"); + if( it != cArr->end() ){ + strncpy( tVal->address, it->second.c_str(),64); + tVal->address[64] = (char)0; + }; + it = cArr->find("mask"); + if( it != cArr->end() ){ + strncpy( tVal->netmask, it->second.c_str(),64); + tVal->netmask[64] = (char)0; + }; + it = cArr->find("broadcast"); + if( it != cArr->end() ){ + strncpy( tVal->broadcast, it->second.c_str(),64); + tVal->broadcast[64] = (char)0; + }; + it = cArr->find("gateway"); + if( it != cArr->end() ){ + strncpy( tVal->gateway, it->second.c_str(),64); + tVal->gateway[64] = (char)0; + }; + }; + }; + }; + deleteResult( result ); + }; + return tVal; +}; + uint32_t sqliteDBC::getNetworkInfrastructureID( uint32_t nif_id ){ uint32_t tVal = 0; if( m_bStoIsConnected ){ @@ -2801,7 +2856,7 @@ TARGET_SEGMENT *sqliteDBC::getRegisteredBubble( uint32_t ID ){ char tQBuf[CTEXT]; AAssoc *result; sprintf(tQBuf, "SELECT * FROM `target_bubbles` WHERE `id`=%d", ID ); -#ifdef DEBUG +#ifdef DEBUG_ALL LOG(tQBuf); #endif result = m_pDataStorage->Query( tQBuf ); @@ -3577,6 +3632,37 @@ DBC_INT_LIST *sqliteDBC::listModules(){ return tVal; }; +DBC_INT_LIST *sqliteDBC::listNetworks( uint32_t nif_id ){ + DBC_INT_LIST * tVal = NULL; + if( m_bStoIsConnected ){ + char tQBuf[CTEXT]; + AAssoc *result; + sprintf(tQBuf, "SELECT `id` FROM `networks` WHERE `nif_id`=%d", nif_id ); +#ifdef DEBUG_ALL + LOG(tQBuf); +#endif + result = m_pDataStorage->Query( tQBuf ); + if( result!= NULL ) { + if( result->size() > 0 ) { + Assoc *cArr; + tVal = new DBC_INT_LIST(); + if( tVal != NULL ) { + Assoc::iterator it; + for(int i=0;isize();i++) { + cArr = result->at(i); + it = cArr->find("id"); + if( it != cArr->end() ){ + tVal->push_back( atoi( it->second.c_str() )); + }; + }; + }; + }; + }; + deleteResult( result ); + }; + return tVal; +}; + DBC_INT_LIST *sqliteDBC::listNewModules( DBC_INT_LIST * old_ids ){ DBC_INT_LIST * tVal = NULL; if( m_bStoIsConnected ){ diff --git a/lib/App/common/SQLite_dataBinder.h b/lib/App/common/SQLite_dataBinder.h index 9c4a467e..27136b00 100644 --- a/lib/App/common/SQLite_dataBinder.h +++ b/lib/App/common/SQLite_dataBinder.h @@ -136,6 +136,7 @@ class sqliteDBC: public dataBinder { virtual DBC_NET_IF_DATA * getNIF_Data( uint32_t ID ); virtual uint32_t getNIF_ID( CSTR key ); virtual uint32_t getNIF_IDbyDevice( CSTR device ); + virtual DBC_NETWORK_DATA * getNetworkData( uint32_t net_id ); virtual uint32_t getNetworkInfrastructureID( uint32_t nif_id ); virtual uint32_t getNodeAuxParam( uint32_t NodeID ); virtual DBC_NODE_DATA * getNodeData( uint32_t ID ); @@ -161,7 +162,8 @@ class sqliteDBC: public dataBinder { virtual DBC_INT_LIST * listLRFSensors(); virtual DBC_INT_LIST * listLRFUploads( uint32_t deviceID ); virtual DBC_INT_LIST * listMediaStreams( uint32_t SiteId, uint8_t listingType = LIST_ALL_RECORDS ); - virtual DBC_INT_LIST * listModules(); + virtual DBC_INT_LIST * listModules(); + virtual DBC_INT_LIST * listNetworks( uint32_t nif_id ); virtual DBC_INT_LIST * listNewModules( DBC_INT_LIST * old_ids ); virtual DBC_INT_LIST * listNewNodes( DBC_INT_LIST * old_ids ); virtual DBC_INT_LIST * listNodeFilters( uint32_t NodeID = 0 ); diff --git a/lib/App/common/deviceNodeCamera.cpp b/lib/App/common/deviceNodeCamera.cpp index b37ecb8b..cb1c4a83 100644 --- a/lib/App/common/deviceNodeCamera.cpp +++ b/lib/App/common/deviceNodeCamera.cpp @@ -455,7 +455,7 @@ bool deviceNodeCamera::create(){ }; m_pProtocol = (protocolPTZ *)new protocolPTZ_ONVIF( tURI, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode); } else { - m_pProtocol = (protocolPTZ *)new protocolPTZ_ONVIF(m_sCamData.onvif_ctrl, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode); + m_pProtocol = (protocolPTZ *)new protocolPTZ_ONVIF( m_sCamData.onvif_ctrl, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode ); }; #ifdef DEBUG_EXTRA LOG("ONVIF-END"); @@ -487,7 +487,7 @@ bool deviceNodeCamera::create(){ m_sCamData.online = true; } else LOG_ERROR("No Proto Created!"); } else { -#ifdef DEBUG_EXTRA +#ifdef DEBUG LOG("Proto is OK"); #endif //Load Presets only if we have protocol @@ -496,7 +496,7 @@ bool deviceNodeCamera::create(){ mojoKernel *tKRNL = mojoKernel::getInstance(); if( tKRNL ) { m_bSkeepPositioningWait = (( tKRNL->getMediaMode() & EVE_OUTPUT_VIDEO ) == EVE_OUTPUT_VIDEO ); -#ifdef DEBUG_EXTRA +#ifdef DEBUG char ttTT[128]; sprintf( ttTT, "Kernel Media Mode:%d", tKRNL->getMediaMode() ); LOG( ttTT ); diff --git a/lib/App/common/kernelEventFilterBubble.cpp b/lib/App/common/kernelEventFilterBubble.cpp index fc1b92e7..f204c904 100644 --- a/lib/App/common/kernelEventFilterBubble.cpp +++ b/lib/App/common/kernelEventFilterBubble.cpp @@ -43,9 +43,8 @@ bool kernelEventFilterBubble::createBubble( TARGET_DATA *ptr ){ tData->system_center.x = ptr->system_target.x; tData->system_center.y = ptr->system_target.y; tData->system_center.z = ptr->system_target.z; - //Only In Case of Disabling - //tData->id = m_pDBC->addRegisteredBubble( tData ); if( createBubbleExt( tData, true, false ) ) return true; + LOG_ERROR("Bubble Creation Failure!"); free( tData ); }; return false; @@ -300,8 +299,8 @@ bool kernelEventFilterBubble::resetAllBubbles(){ bool kernelEventFilterBubble::validateTarget( uint32_t DevID, TARGET_DATA *ptr ){ bool RetValue = false; - TARGET_SEGMENT *cBubble = NULL; if( m_bActive && ( ptr != NULL ) ){ + TARGET_SEGMENT *cBubble = NULL; m_mDataProtector.lock(); if ( m_vTargetBubbles.size() ) { for( V_TARGET_SEGMENTS::iterator idx = m_vTargetBubbles.begin(); idx != m_vTargetBubbles.end(); idx++ ){ @@ -348,16 +347,20 @@ bool kernelEventFilterBubble::validateTarget( uint32_t DevID, TARGET_DATA *ptr ) ptr->lrf_id = cBubble->segment_id & 0xFF; ptr->segment_id = cBubble->segment_id; if ( cBubble->mode == TS_MODE_BLOCKED ) { + //Temporary (untill Session End ) createFilterEvent(EVT_FLT_BUBBLE_BLOCK_T, ptr ); } else { + //Permanent createFilterEvent(EVT_FLT_BUBBLE_BLOCK_P, ptr ); }; }; + //Block Target Propagation RetValue = true; }; } else { // The Bubble was not found nor Regular nor Frozen -> Creating New RetValue = createBubble( ptr ); + //On Creation TRUE must be returned so the target will be blocked }; }; return RetValue; diff --git a/lib/App/common/kernelModuleEmbedVideo.h b/lib/App/common/kernelModuleEmbedVideo.h index 40910b61..35359acc 100644 --- a/lib/App/common/kernelModuleEmbedVideo.h +++ b/lib/App/common/kernelModuleEmbedVideo.h @@ -214,7 +214,7 @@ typedef map mapSTREAMMAPS; //#define ENCODER_DISABLED 0 //#define ENCODER_ENABLED 1 -#define EVE_ENABLE_EASE_OUTPUT_FPS +//#define EVE_ENABLE_EASE_OUTPUT_FPS #ifdef EVE_ENABLE_EASE_OUTPUT_FPS #define EVE_EASE_FPS_DIVIDER_MINIMUM 1 diff --git a/lib/App/common/kernelPrototype.cpp b/lib/App/common/kernelPrototype.cpp index 8fbfcf0d..3a933cfe 100644 --- a/lib/App/common/kernelPrototype.cpp +++ b/lib/App/common/kernelPrototype.cpp @@ -1,14 +1,14 @@ #include "kernelPrototype.h" -#define LOG( X ) kernelPrototype::m_pLog->Log( "KRNL", this, X ) +#define LOG( X ) kernelPrototype::m_pLog->Log( "PROTOKRNL", this, X ) #ifdef DEBUG #define LOG_ERROR( X ) {\ char _tBfrErrMSG234[256];\ sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ - kernelPrototype::m_pLog->Log( "KRNL", this, _LOG_ERROR, _tBfrErrMSG234 );\ + kernelPrototype::m_pLog->Log( "PROTOKRNL", this, _LOG_ERROR, _tBfrErrMSG234 );\ } #else - #define LOG_ERROR( X ) kernelPrototype::m_pLog->Log( "KRNL", this, _LOG_ERROR, X ); + #define LOG_ERROR( X ) kernelPrototype::m_pLog->Log( "PROTOKRNL", this, _LOG_ERROR, X ); #endif kernelPrototype *kernelPrototype::_instance = NULL; @@ -80,7 +80,7 @@ kernelPrototype::~kernelPrototype(){ #ifdef LINUX_KERNEL_WATCHDOG LOG("Closing WD!"); if( !( m_iWatchdogFd < 0 ) ) close( m_iWatchdogFd ); - LOG("WatchDog turned Off!"); + LOG("WatchDog Closed!"); #endif }; diff --git a/lib/App/common/targetPipeLine.cpp b/lib/App/common/targetPipeLine.cpp index c95f3155..12ac81d5 100644 --- a/lib/App/common/targetPipeLine.cpp +++ b/lib/App/common/targetPipeLine.cpp @@ -29,13 +29,11 @@ targetPipeLine::targetPipeLine( uint32_t node_id, uint32_t bind_cam_id):basicThr #else m_pDBC = sqliteDBC::getInstance(); #endif - LOG("Construct"); loadFilters(); init(); }; targetPipeLine::~targetPipeLine(){ - LOG("Destruct"); waitThreadEnd( true ); if ( m_vTargetFilters.size() ) m_vTargetFilters.clear(); while ( m_qTargets.size() ){ @@ -43,7 +41,6 @@ targetPipeLine::~targetPipeLine(){ m_qTargets.pop(); free( tData ); }; - LOG("Done"); }; void targetPipeLine::m_fThreadProc( void ){ @@ -111,19 +108,29 @@ bool targetPipeLine::loadFilters(){ LOG_ERROR("KERNEL <<< GRAB >>> Failure!"); return false; }; - LOG("Loading Filters To Sensor's PipeLine"); +#ifdef DEBUG + LOG("Assigning Filters To Sensor's PipeLine"); +#endif DBC_INT_LIST *IDS = m_pDBC->listNodeFilters( m_nNodeId ); if ( IDS ) { if ( IDS->size() ) { for ( DBC_INT_LIST::iterator idx = IDS->begin(); idx != IDS->end(); idx++ ) { - LOG("Loadded Filter To Sensor's PipeLine"); +#ifdef DEBUG_EXTRA + LOG("Request Filter from Kernel"); +#endif kernelEventFilter * tFilter = AK->getFilter( *idx ); if( tFilter ) m_vTargetFilters.push_back( tFilter ); }; }; delete(IDS); +#ifdef DEBUG + LOG("Assigning Filters Done"); +#endif return true; }; +#ifdef DEBUG + LOG("No Filters to Assign!"); +#endif }; return false; }; diff --git a/lib/App/mojo/mojoKernel.cpp b/lib/App/mojo/mojoKernel.cpp index b8243480..2baa8241 100644 --- a/lib/App/mojo/mojoKernel.cpp +++ b/lib/App/mojo/mojoKernel.cpp @@ -698,28 +698,41 @@ void mojoKernel::m_fThreadProc( void ){ void mojoKernel::loadFilters(){ if( m_pDBC == NULL ) return; +#ifdef DEBUG + LOG("Loadding Filters ..."); +#endif DBC_INT_LIST *tList = m_pDBC->listFilters( m_nServerID ); if( tList != NULL ) { if( tList->size() > 0 ) { - LOG("Have Filters!"); for( DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ) { +#ifdef DEBUG_EXTRA LOG("Load Filter!"); +#endif DBC_TARGET_FLITER_DATA *tData = NULL; tData = m_pDBC->getTargetFilterData( (*idx) ); if( tData != NULL ) { +#ifdef DEBUG_EXTRA LOG("Filter Data OK!"); +#endif switch( tData->type ) { case TF_LA_METRO_TRAIN_FILTER:{ +#ifdef DEBUG LOG("Create Train Filter"); +#endif kernelEventFilterTrain *tFilter = new kernelEventFilterTrain( (*idx) ); if( tFilter != NULL ) { if( tFilter->initFilter() ){ +#ifdef DEBUG + LOG("Add Train Filter"); +#endif m_vTargetFilters.push_back( (kernelEventFilter*) tFilter ); } else { +#ifdef DEBUG + LOG_ERROR("Error in Filter Init!"); +#endif delete( tFilter ); }; }; - LOG("Added Train Filter"); break; }; case TF_AUTHORISED_PEOPLE_FILTER: { @@ -727,41 +740,60 @@ void mojoKernel::loadFilters(){ kernelEventFilterAPF *tFilter = new kernelEventFilterAPF( (*idx) ); if( tFilter != NULL ) { if( tFilter->initFilter() ){ +#ifdef DEBUG + LOG("Add APF"); +#endif m_vTargetFilters.push_back( (kernelEventFilter*) tFilter ); } else { +#ifdef DEBUG + LOG_ERROR("Error in Filter Init!"); +#endif delete( tFilter ); }; - }; - LOG("Added APF"); + }; break; }; case TF_BUBBLE_SEGMENTATION_FILTER:{ +#ifdef DEBUG LOG("Create Bubble Filter"); +#endif kernelEventFilterBubble *tFilter = new kernelEventFilterBubble( (*idx) ); if( tFilter != NULL ) { +#ifdef DEBUG_EXTRA LOG("Init Bubble Filter"); +#endif if( tFilter->initFilter() ){ +#ifdef DEBUG LOG("Add Bubble Filter"); +#endif m_vTargetFilters.push_back( (kernelEventFilter*) tFilter ); } else { +#ifdef DEBUG + LOG_ERROR("Error in Filter Init!"); +#endif delete( tFilter ); }; }; - LOG("Added Bubble Filter"); break; }; case TF_YOLO_FILTER:{ break; }; }; +#ifdef DEBUG_EXTRA LOG("Delete Filter Data"); +#endif free( tData ); }; }; +#ifdef DEBUG_EXTRA LOG("Clear Filter List"); +#endif tList->clear(); }; +#ifdef DEBUG_EXTRA LOG("Delete Filter List"); +#endif delete( tList ); #ifdef DEBUG } else { @@ -788,6 +820,15 @@ void mojoKernel::unloadFilters(){ delete( (kernelEventFilterAPF*)(*idx) ); break; }; + case TF_BUBBLE_SEGMENTATION_FILTER:{ + delete( (kernelEventFilterBubble*)(*idx) ); + break; + }; + case TF_YOLO_FILTER:{ + //ToDo: Must be changed according to Steph's code + //delete( (kernelEventFilterYOLO*)(*idx) ); + break; + }; default:{ char tBuffer[64]; sprintf( tBuffer, "Unknown Filter: %d", (*idx)->getType() ); diff --git a/lib/App/mojo/mojoRemoteClient.cpp b/lib/App/mojo/mojoRemoteClient.cpp index a8c629aa..c9a938c0 100644 --- a/lib/App/mojo/mojoRemoteClient.cpp +++ b/lib/App/mojo/mojoRemoteClient.cpp @@ -830,6 +830,8 @@ bool mojoRemoteClient::peer_send_rpc_pack( RPC_CMD_RECORD *ptr ){ */ bool mojoRemoteClient::validate(){ if( m_bCommunicationEstablished ){ +#if 0 +lk;sdf if ( getConnectionStatus() == CS_DISCONNECTED ) { m_bCommunicationEstablished = false; if( m_pPort ) { @@ -841,7 +843,7 @@ bool mojoRemoteClient::validate(){ m_bAutomationStage = ARGUS_RPC_STAGE_CONNECT; // Revalidate Data!!! //m_bActiveServer = 0; - //m_bUseBackupServer = ( ( m_pMaster->m_sSiteData.remote_backup_port > 0 ) && strlen( ( m_pMaster->m_sSiteData.remote_backup_ip ) > 7 ) ); + m_bUseBackupServer = ( ( m_pMaster->m_sSiteData.remote_backup_port > 0 ) && strlen( ( m_pMaster->m_sSiteData.remote_backup_ip ) > 7 ) ); /*m_pPort = new clientPort( m_pMaster->m_sSiteData.remote_ip, m_pMaster->m_sSiteData.remote_port ); if( m_pPort ) { @@ -857,6 +859,8 @@ bool mojoRemoteClient::validate(){ }; */ }; +#endif + #ifdef DEBUG_EXTRA } else { LOG("Not Connected!"); diff --git a/lib/data/net/clientPort.cpp b/lib/data/net/clientPort.cpp index b308b9c2..316c8990 100644 --- a/lib/data/net/clientPort.cpp +++ b/lib/data/net/clientPort.cpp @@ -64,11 +64,11 @@ clientPort::clientPort(CSTR Host, int Port, bool KeepALive ) :transportSocket(){ }; clientPort::~clientPort(){ -#ifdef DEBUG +#ifdef DEBUG_EXTRA LOG("Destructor!"); #endif disconnect(); -#ifdef DEBUG +#ifdef DEBUG_EXTRA LOG("Disconnected!"); LOG("Destructor Done!"); #endif @@ -85,7 +85,7 @@ bool clientPort::create(){ return false; }; if( connectTo( m_cHostName, m_nPort ) ){ -#ifdef DEBUG +#ifdef DEBUG_EXTRA char tB[256]; sprintf(tB, "Connect %s [%d] OK", m_cHostName, m_nPort); LOG(tB); @@ -94,13 +94,16 @@ bool clientPort::create(){ if ( m_nReaderSetMax < m_nSocketFD ) m_nReaderSetMax = m_nSocketFD; return transportSocket::create(); } else { +#ifdef DEBUG_EXTRA LOG_ERROR("Cannot Connect!"); +#endif }; return false; }; bool clientPort::_connect(void){ int iResult; + long arg; struct addrinfo * result, *ptr, hints; char cBuffer[256]; struct sockaddr_in serv_addr; @@ -121,17 +124,83 @@ bool clientPort::_connect(void){ serv_addr.sin_family = AF_INET; bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length ); serv_addr.sin_port = htons( m_nPort ); - if ( connect(m_nSocketFD,(struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0){ - sprintf(cBuffer,"ERROR connect to [%s:%d] error: %d", m_cHostName, m_nPort, errno ); - LOG_ERROR( cBuffer ); - return false; - }; -#ifdef CLIENT_SOCKET_NON_BLOCKING - if ( fcntl(m_nSocketFD, F_SETFL, fcntl(m_nSocketFD, F_GETFL, 0) | O_NONBLOCK) < 0 ){ - sprintf(cBuffer,"ERROR cannot set NONBLOCK error: %d", errno ); - LOG_ERROR( cBuffer ); - return false; + fd_set fdset; + struct timeval tv; + + if( ( arg = fcntl( m_nSocketFD, F_GETFL, NULL)) < 0) { + sprintf( cBuffer, "Error fcntl(..., F_GETFL) (%s)", strerror(errno) ); + LOG_ERROR(cBuffer); + return false; + }; + arg |= O_NONBLOCK; + if( fcntl( m_nSocketFD, F_SETFL, arg) < 0) { + sprintf( cBuffer, "Error fcntl(..., F_SETFL) (%s)", strerror(errno) ); + LOG_ERROR(cBuffer); + return false; + }; + + // Trying to connect with timeout + iResult = connect( m_nSocketFD, (struct sockaddr *)&serv_addr, sizeof(serv_addr)); + if( iResult < 0 ){ + if( errno == EINPROGRESS ){ + //LOG("EINPROGRESS in connect() - selecting"); + do { + tv.tv_sec = 15; + tv.tv_usec = 0; + FD_ZERO( &fdset ); + FD_SET( m_nSocketFD, &fdset ); + iResult = select( m_nSocketFD+1, NULL, &fdset, NULL, &tv ); + if( iResult < 0 && errno != EINTR ) { +#ifdef DEBUG + sprintf( cBuffer, "Error connecting %d - %s", errno, strerror(errno) ); + LOG_ERROR(cBuffer); +#endif + return false; + } else if ( iResult > 0) { + // Socket selected for write + socklen_t par = sizeof(int); + if( getsockopt( m_nSocketFD, SOL_SOCKET, SO_ERROR, (void*)(&iResult), &par) < 0 ){ +#ifdef DEBUG + sprintf( cBuffer, "Error in getsockopt() %d - %s", errno, strerror(errno) ); + LOG_ERROR(cBuffer); +#endif + return false; + }; + // Check the value returned... + if( iResult ){ +#ifdef DEBUG + sprintf( cBuffer, "Error in delayed connection() %d - %s", iResult, strerror(iResult) ); + LOG_ERROR(cBuffer); +#endif + return false; + }; + break; + } else { +#ifdef DEBUG + LOG_ERROR( "Timeout in select() - Cancelling!" ); +#endif + return false; + }; + } while (1); + } else { +#ifdef DEBUG + sprintf( cBuffer, "Error connecting %d - %s", errno, strerror(errno) ); + LOG_ERROR(cBuffer); +#endif + return false; + }; }; +#if 0 + // Set to blocking mode again... + if( (arg = fcntl(soc, F_GETFL, NULL)) < 0) { + fprintf(stderr, "Error fcntl(..., F_GETFL) (%s)\n", strerror(errno)); + exit(0); + } + arg &= (~O_NONBLOCK); + if( fcntl(soc, F_SETFL, arg) < 0) { + fprintf(stderr, "Error fcntl(..., F_SETFL) (%s)\n", strerror(errno)); + exit(0); + } #endif #else // Initialize Winsock