Skip to content

Commit

Permalink
Merge pull request #684 from rhomobile/Win32_network_patch
Browse files Browse the repository at this point in the history
Hi Simha,patch for network crash
  • Loading branch information
fgqw68 committed Jul 30, 2015
2 parents 557c0da + 316ea0c commit e9ac00c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 6 deletions.
49 changes: 49 additions & 0 deletions lib/commonAPI/coreapi/ext/shared/NetworkDetectBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,31 @@ bool CNetworkDetectionBase::SetNetworkPollInterval(int iInterval)
return false;
}
}
#if defined(RHODES_QT_PLATFORM) && defined(OS_WINDOWS_DESKTOP)
HANDLE g_hThread =NULL;
HANDLE g_hStopEvent = NULL;

DWORD WINAPI runProc(LPVOID detectionObjPtr)
{

CNetworkDetectionBase* ptr = (CNetworkDetectionBase*)detectionObjPtr;

while( 1 )
{
if(ptr->CheckConnectivity())
{
break;
}
DWORD dwRes = ::WaitForSingleObject( g_hStopEvent, ptr->getPollInterval() );
if(dwRes == WAIT_OBJECT_0)
{
break;
}

}
return 0;
}
#endif

/**
* \author Darryn Campbell (DCC, JRQ768)
Expand All @@ -89,7 +114,15 @@ bool CNetworkDetectionBase::SetNetworkPollInterval(int iInterval)
bool CNetworkDetectionBase::StartNetworkChecking()
{
m_NetworkState = NETWORK_INITIALISING;
#if defined(RHODES_QT_PLATFORM) && defined(OS_WINDOWS_DESKTOP)

g_hStopEvent = ::CreateEvent(NULL, FALSE, FALSE, NULL);
g_hThread = ::CreateThread(NULL, 0, runProc, this, 0, NULL);

#else
start(epNormal);
#endif

return true;
}

Expand All @@ -100,7 +133,23 @@ bool CNetworkDetectionBase::StartNetworkChecking()
bool CNetworkDetectionBase::StopNetworkChecking()
{
// Only stop the network checking if it is currently running

#if defined(RHODES_QT_PLATFORM) && defined(OS_WINDOWS_DESKTOP)
if(g_hStopEvent && g_hThread)
{
::SetEvent(g_hStopEvent);
::WaitForSingleObject( g_hThread, INFINITE );
CloseHandle(g_hThread);
CloseHandle(g_hStopEvent);
}
g_hThread = NULL;
g_hStopEvent = NULL;

#else
stop(60000);
#endif


return true;
}

Expand Down
4 changes: 3 additions & 1 deletion lib/commonAPI/coreapi/ext/shared/NetworkDetectBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ class CNetworkDetectionBase : public rho::common::CRhoThread, public INetworkDe
virtual bool IsChecking();
virtual void SetCallback(rho::apiGenerator::CMethodResult pCallback);
virtual rho::apiGenerator::CMethodResult GetCallback() {return m_pDetectCallback;}
virtual bool CheckConnectivity() = 0;
int getPollInterval(){return m_iNetworkPollInterval;}

protected: // Methods
virtual bool CheckConnectivity() = 0;


virtual void Startup() = 0;
virtual void Cleanup() = 0;
Expand Down
9 changes: 8 additions & 1 deletion lib/commonAPI/coreapi/ext/shared/NetworkImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,15 @@ void CNetworkImpl::detectConnection( const rho::Hashtable<rho::String, rho::Stri
// m_networkPollers.push_back(pNetworkDetection);
if ( m_networkPoller != 0 )
{
m_networkPoller->CleanupAndDeleteSelf();
#if defined(RHODES_QT_PLATFORM) && defined(OS_WINDOWS_DESKTOP)
m_networkPoller->StopNetworkChecking();
delete m_networkPoller;
#else
m_networkPoller->CleanupAndDeleteSelf();
#endif

m_networkPoller = 0;

}

m_networkPoller = pNetworkDetection;
Expand Down
8 changes: 4 additions & 4 deletions platform/shared/qt/rhodes/impl/RhoClassFactoryImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
#include "common/RhoDefs.h"
#include "common/IRhoClassFactory.h"
#ifdef OS_WINDOWS_DESKTOP
#ifdef RHO_SYMBIAN
#include "rho/common/RhoThreadImpl.h"
#else // RHO_SYMBIAN
//#ifdef RHO_SYMBIAN
//#include "rho/common/RhoThreadImpl.h"
//#else // RHO_SYMBIAN
#include "RhoThreadImpl.h"
#endif // RHO_SYMBIAN
//#endif // RHO_SYMBIAN
#include "rho/net/NetRequestImpl.h"
#define CNETREQUESTIMPL new net::CNetRequestImpl()
#define CRHOTHREADIMPL new CRhoThreadImpl()
Expand Down

0 comments on commit e9ac00c

Please sign in to comment.