Click to See Complete Forum and Search --> : How to detect lost net connection


DRowell
June 2nd, 2004, 05:17 PM
I'm working on an MFC C++ app that can connect to Oracle over the net and I need to detect (within 1-2 seconds) when the network connection has been lost.

I've tried several approaches in a worker thread:

I've tried NotifyChangeEventLog with WaitForSingleObject to catch additions to the System Event log. However TCPIP entries there relating to connection loss sometimes take as much as 8 seconds to show up.

I get better response using WMI to query for Win32_NetworkAdapter instance modification events with this query (it polls every 2 seconds):

select * from __InstanceModificationEvent within 2 where TargetInstance isa \"Win32_NetworkAdapter\" and PreviousInstance.NetConnectionStatus = 2 and TargetInstance.NetConnectionStatus <> 2

However, I see a CPU hit (~20% utilization every two seconds), and that seems rather expensive.

Does anyone know of another approach that is responsive and does not involve so much CPU work.

Thanks.

VipulPathak
June 3rd, 2004, 07:04 AM
How you connect to Oracle ? Can you post a small code snippet ?

Regards.

-Vipul Pathak ;

DRowell
June 3rd, 2004, 09:22 AM
I'm logging in using Oracle Objects For OLE (OO4O), Oracle's C++ API. Something like:

ODatabase m_oracleDatabase;

...

oresult orc = m_oracleDatabase.Open(
dbname, username, password, _defaultOpenMode);

It's not like I have a socket, and even if I did, we don't want to use pinging because it's often blocked for security reasons.

j0nas
June 3rd, 2004, 04:01 PM
Another approach is to implement a timeout... If there is no timeout options for the network functions you're dealing with, you can create/simulate a timeout by having blocking calls in a worker thread.