Browse Source

Improved open() and close() functions to be able to repeatedly open and close udp port

tags/1.0
Ludwig Frühschütz 3 years ago
parent
commit
1841ebb220
1 changed files with 21 additions and 1 deletions
  1. +21
    -1
      OSC2AHK/dllmain.cpp

+ 21
- 1
OSC2AHK/dllmain.cpp View File

@ -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…
Cancel
Save