Improved open() and close() functions to be able to repeatedly open and close udp port
This commit is contained in:
		
							parent
							
								
									406baef516
								
							
						
					
					
						commit
						1841ebb220
					
				| @ -85,12 +85,16 @@ BOOL APIENTRY DllMain( HMODULE hModule, | ||||
|     switch (ul_reason_for_call) | ||||
|     { | ||||
|     case DLL_PROCESS_ATTACH: | ||||
|         OutputDebugString(L"DLL_PROCESS_ATTACH\r\n"); | ||||
|         break; | ||||
|     case DLL_THREAD_ATTACH: | ||||
|         OutputDebugString(L"DLL_THREAD_ATTACH\r\n"); | ||||
|         break; | ||||
|     case DLL_THREAD_DETACH: | ||||
|         OutputDebugString(L"DLL_THREAD_DETACH\r\n"); | ||||
|         break; | ||||
|     case DLL_PROCESS_DETACH: | ||||
|         OutputDebugString(L"DLL_THREAD_DETACH\r\n"); | ||||
|         close(); | ||||
|         break; | ||||
|     } | ||||
| @ -105,6 +109,20 @@ DLLEXPORT int open(HWND targetWindowHandle, unsigned int port) | ||||
|         if (!port) OutputDebugString(L"open: port!!\r\n"); | ||||
|         return 1; | ||||
|     } | ||||
|      | ||||
|     //Check if sock is currently free to use
 | ||||
|     if (sock) | ||||
|     { | ||||
|         if (sock->IsBound()) //Sock is currently opened. User should call close() first!
 | ||||
|         { | ||||
|             OutputDebugString(L"open: seems to be opened already!\r\n"); | ||||
|             return 3; | ||||
|         } | ||||
|         else //Probably something went wrong in UDP socket, just try closing and reopening it...
 | ||||
|         { | ||||
|             close(0); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     unsigned int timeout = 500; //timout for port opening, in ms
 | ||||
| 
 | ||||
| @ -134,7 +152,9 @@ DLLEXPORT int close(unsigned int clearListeners) | ||||
|     { | ||||
|         sock->AsynchronousBreak(); | ||||
|     } | ||||
|     oscThread->join(); | ||||
|     if(oscThread) oscThread->join(); | ||||
|     delete sock; | ||||
|     sock = nullptr; | ||||
|     oscThread = NULL; | ||||
|     hwnd = NULL; | ||||
|     if (clearListeners) listeners.clear(); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user