1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Tweaked OSCReceiver to make sure it shuts down more cleanly

This commit is contained in:
jules 2018-07-10 17:15:49 +01:00
parent 426e122375
commit b14988fb1d

View file

@ -60,7 +60,7 @@ namespace
size_t getDataSize() const noexcept { return input.getDataSize(); } size_t getDataSize() const noexcept { return input.getDataSize(); }
/** Returns the current position of the stream. */ /** Returns the current position of the stream. */
uint64 getPosition() { return uint64 (input.getPosition()); } uint64 getPosition() { return (uint64) input.getPosition(); }
/** Attempts to set the current position of the stream. Returns true if this was successful. */ /** Attempts to set the current position of the stream. Returns true if this was successful. */
bool setPosition (int64 pos) { return input.setPosition (pos); } bool setPosition (int64 pos) { return input.setPosition (pos); }
@ -295,7 +295,7 @@ namespace
OSCMessage readMessageWithCheckedSize (size_t size) OSCMessage readMessageWithCheckedSize (size_t size)
{ {
auto begin = (size_t) getPosition(); auto begin = (size_t) getPosition();
OSCMessage message (readMessage()); auto message = readMessage();
if (getPosition() - begin != size) if (getPosition() - begin != size)
throw OSCFormatError ("OSC input stream format error: wrong element content size encountered while reading"); throw OSCFormatError ("OSC input stream format error: wrong element content size encountered while reading");
@ -363,6 +363,7 @@ struct OSCReceiver::Pimpl : private Thread,
waitForThreadToExit (10000); waitForThreadToExit (10000);
socket.reset(); socket.reset();
} }
return true; return true;
} }
@ -458,12 +459,15 @@ private:
while (! threadShouldExit()) while (! threadShouldExit())
{ {
jassert (socket != nullptr); jassert (socket != nullptr);
char buffer[oscBufferSize]; auto ready = socket->waitUntilReady (true, 100);
socket->waitUntilReady (true, -1);
if (threadShouldExit()) if (ready < 0 || threadShouldExit())
return; return;
if (ready == 0)
continue;
char buffer[oscBufferSize];
auto bytesRead = (size_t) socket->read (buffer, (int) sizeof (buffer), false); auto bytesRead = (size_t) socket->read (buffer, (int) sizeof (buffer), false);
if (bytesRead >= 4) if (bytesRead >= 4)
@ -880,7 +884,7 @@ public:
OSCInputStream inStream (data, sizeof (data)); OSCInputStream inStream (data, sizeof (data));
OSCMessage msg = inStream.readMessage(); auto msg = inStream.readMessage();
expect (msg.getAddressPattern().toString() == "/test"); expect (msg.getAddressPattern().toString() == "/test");
expect (msg.size() == 0); expect (msg.size() == 0);
} }
@ -954,7 +958,7 @@ public:
OSCInputStream inStream (data, sizeof (data)); OSCInputStream inStream (data, sizeof (data));
OSCMessage msg = inStream.readMessage(); auto msg = inStream.readMessage();
expectEquals (msg.getAddressPattern().toString(), String ("/test")); expectEquals (msg.getAddressPattern().toString(), String ("/test"));
expectEquals (msg.size(), 4); expectEquals (msg.size(), 4);