Link to home
Start Free TrialLog in
Avatar of TomPro
TomProFlag for United States of America

asked on

Windows 2003 -- RasHangUp blocks for several seconds before returning, and handle count keeps climbing?

I am using RAS to create and disconnect VPN connections.  I can establish the connection without any problems and transfer data across it.  However, I am experiencing two issues:

1.  RasDial blocks for about 5 seconds before returning.
2.  According to Task Manager, the program's handle count is steadily increasing, even though I am careful to give RAS enough time to release the handle.


Here is my hangup code, :

int hangup(HRASCONN* vpnConn)
   {

   DWORD RASDialStatus = -1;
   RASCONNSTATUS vpnConnStatus;

   memset ((void*) &vpnConnStatus, 0, sizeof(RASCONNSTATUS));
   vpnConnStatus.dwSize = sizeof(RASCONNSTATUS);

   RASDialStatus = RasHangUp(*vpnConn);
   

   if (!RASDialStatus)
      {
      while (RASDialStatus != ERROR_INVALID_HANDLE)
         {
         RASDialStatus = RasGetConnectStatus (*vpnConn, &vpnConnStatus);
         Sleep(0);
         }
      }

   /* Error handling stuff goes here */

   }


I thought at first that the while() loop was causing the delay.  However, when I step through the code, RasHangup() blocks for about 5 seconds before it returns 0.  The while loop runs just once before the RasGetConnectStatus returns ERROR_INVALID_HANDLE.

Does anyone know what might be causing RasHangup to take so long to return?  Could it be something in the way that I am initializing the connection properties when I call RasDial?

Thanks!
Avatar of grg99
grg99

I would not worry about the delay.   If it's troublesome you could always run that  code in a separate thread.

Avatar of TomPro

ASKER

Unfortunately, the delay *is* an issue.  The program depends on retrieving data over VPN connections as quickly as possible.  It's important to have the user wait as little as possible as the program makes up to 20 consecutive VPN connections to locate information.  

Even cutting the delay down from 5 seconds to 3 seconds per connection could make considerable difference for our end users.
Avatar of TomPro

ASKER

Does anyone have any additional insight on this issue?

Thanks!
You could spin off each connection as a separate thread, unless there is some concurrency issue.   With a little luck you could have everything happening in parallel instead of serially.



Avatar of TomPro

ASKER

grg99, this approach is a good idea except for one problem:  the IP address that I access once I open the VPN is the same for each VPN connection.  

In other words, if I have VPN firewalls with external addresses a.a.a.a, b.b.b.b, and c.c.c.c, once I connect to each, my program interacts with a system at address e.e.e.e behind the VPN.

Also, I am still searching for an answer to why I am seeing an increase in handle count each time the posted code runs.

Thanks guys!
ASKER CERTIFIED SOLUTION
Avatar of TomPro
TomPro
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial