I have a program that runs on my wife's computer (she lives out of state) which she uses when she is or is not VPN'd into the home computer. The problem that I'm having is that I cannot detect when she has disconnected the VPN and the home computer drive is no longer available. GetLogicalDrives() continues to show the V: drive is available even after she disconnects. The problem is I then call GetFileAttributesEx() which hangs for about 30 seconds so it makes it look like my program is not responding to her.
The following code is basically what I'm using:
int main()
{
#define DRIVE 'V' // VPN drive
#define FILE "V:\\Folder\\File.txt" // file on VPN drive
WIN32_FILE_ATTRIBUTE_DATA attribute;
for ( ; ; ) {
Sleep(10000); // 10 seconds
// Check if DRIVE is available
if (GetLogicalDrives() & (1 << (DRIVE - 'A'))) {
// Getting here even though VPN has been disconnected
fprintf(stdout, "Drive %c: is available\n", DRIVE);
// Now get the attibutes of FILE, but when VPN is disconnected, this
// hangs for about 30 seconds before returning ERROR_BAD_NETPATH (53)
if (!GetFileAttributesEx(FILE, GetFileExInfoStandard, &attribute)) {
fprintf(stdout, "GetFileAttributesEx() failed, error = %d\n", GetLastError());
continue;
}
fprintf(stdout, "All is ok\n");
}
else fprintf(stdout, "Drive %c: is unavailable\n", DRIVE);
}
return 0;
}
Any suggestions on how to prevent getting hungup for 30 seconds on the GetFileAttributesEx() call after she disconnects her VPN session? I will also need to detect when she reconnects her VPN session.