Browse Source

Build fix in tap, handling of Windows shutdown signals.

Adam Ierymenko 12 years ago
parent
commit
c247a3d991
2 changed files with 19 additions and 1 deletions
  1. 18 0
      main.cpp
  2. 1 1
      node/EthernetTap.cpp

+ 18 - 0
main.cpp

@@ -107,6 +107,23 @@ static void sighandlerQuit(int sig)
 }
 #endif
 
+#ifdef __WINDOWS__
+static BOOL WINAPI _handlerRoutine(DWORD dwCtrlType)
+{
+	switch(dwCtrlType) {
+		case CTRL_C_EVENT:
+		case CTRL_BREAK_EVENT:
+		case CTRL_CLOSE_EVENT:
+		case CTRL_SHUTDOWN_EVENT:
+			Node *n = node;
+			if (n)
+				n->terminate();
+			return TRUE;
+	}
+	return FALSE;
+}
+#endif
+
 #ifdef __WINDOWS__
 int _tmain(int argc, _TCHAR* argv[])
 #else
@@ -127,6 +144,7 @@ int main(int argc,char **argv)
 #ifdef __WINDOWS__
 	WSADATA wsaData;
 	WSAStartup(MAKEWORD(2,2),&wsaData);
+	SetConsoleCtrlHandler(&_handlerRoutine,TRUE);
 #endif
 
 	_initLibCrypto();

+ 1 - 1
node/EthernetTap.cpp

@@ -1017,7 +1017,7 @@ void EthernetTap::setDisplayName(const char *dn)
 {
 	HKEY ifp;
 	if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,(std::string("SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\") + _myDeviceInstanceId).c_str(),0,KEY_READ|KEY_WRITE,&ifp) == ERROR_SUCCESS) {
-		RegSetKeyValueA(ifp,"Connection","Name",REG_SZ,(LPCVOID)dn,strlen(dn)+1);
+		RegSetKeyValueA(ifp,"Connection","Name",REG_SZ,(LPCVOID)dn,(DWORD)(strlen(dn)+1));
 		RegCloseKey(ifp);
 	}
 }