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

IPC: Allow setting custom timeouts in disconnect

Also allows optionally ignoring callbacks during disconnect, so that the
call to `connectionLost` can be bypassed when disconnect is called from
the derived class destructor.
This commit is contained in:
reuk 2020-11-02 12:51:17 +00:00
parent 750c982c1d
commit a70101e3ec
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11
2 changed files with 14 additions and 5 deletions

View file

@ -89,7 +89,7 @@ InterprocessConnection::~InterprocessConnection()
jassert (! safeAction->isSafe());
callbackConnectionState = false;
disconnect();
disconnect (4000, Notify::no);
thread.reset();
}
@ -145,7 +145,7 @@ bool InterprocessConnection::createPipe (const String& pipeName, int timeoutMs,
return false;
}
void InterprocessConnection::disconnect()
void InterprocessConnection::disconnect (int timeoutMs, Notify notify)
{
thread->signalThreadShouldExit();
@ -155,10 +155,13 @@ void InterprocessConnection::disconnect()
if (pipe != nullptr) pipe->close();
}
thread->stopThread (4000);
thread->stopThread (timeoutMs);
deletePipeAndSocket();
connectionLostInt();
if (notify == Notify::yes)
connectionLostInt();
callbackConnectionState = false;
safeAction->setSafe (false);
}

View file

@ -120,12 +120,18 @@ public:
*/
bool createPipe (const String& pipeName, int pipeReceiveMessageTimeoutMs, bool mustNotExist = false);
/** Whether the disconnect call should trigger callbacks. */
enum class Notify { no, yes };
/** Disconnects and closes any currently-open sockets or pipes.
Derived classes *must* call this in their destructors in order to avoid undefined
behaviour.
@param timeoutMs the time in ms to wait before killing the thread by force
@param notify whether or not to call `connectionLost`
*/
void disconnect();
void disconnect (int timeoutMs = -1, Notify notify = Notify::yes);
/** True if a socket or pipe is currently active. */
bool isConnected() const;