Browse Source

Catch runtime error when port cannot be opened. closes #5

tags/0.3
Ludwig Frühschütz 3 years ago
parent
commit
31c53da91f
1 changed files with 23 additions and 5 deletions
  1. +23
    -5
      OSC2AHK/dllmain.cpp

+ 23
- 5
OSC2AHK/dllmain.cpp View File

@ -63,11 +63,16 @@ void runOscThread(unsigned int port)
thePacketListener = new ThePacketListener;
if (sock) sock->~UdpListeningReceiveSocket();
sock = new UdpListeningReceiveSocket(
IpEndpointName(IpEndpointName::ANY_ADDRESS, port),
thePacketListener);
sock->RunUntilSigInt(); //<<--- this is the loop
try {
sock = new UdpListeningReceiveSocket(
IpEndpointName(IpEndpointName::ANY_ADDRESS, port),
thePacketListener);
sock->RunUntilSigInt(); //<<--- this is the loop
}
catch (std::runtime_error)
{
OutputDebugString(L"Unable to open port!\r\n");
}
}
/* DLL was loaded */
@ -100,11 +105,24 @@ DLLEXPORT int open(HWND targetWindowHandle, unsigned int port)
return 1;
}
unsigned int timeout = 500; //timout for port opening, in ms
/*Store handle to Autohotkey window globally*/
hwnd = targetWindowHandle;
/*Start OSC Thread*/
oscThread = new std::thread(runOscThread, port);
while ((!sock || !sock->IsBound()) && timeout)
{
timeout--;
Sleep(1);
}
if (!sock || !sock->IsBound())
{
OutputDebugString(L"open: cannot open port!!\r\n");
return 2;
}
OutputDebugString(L"open: Opened.\r\n");
return 0;
}


Loading…
Cancel
Save