mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Added a timeout value to the ChildProcessSlave and ChildProcessMaster classes.
This commit is contained in:
parent
a9750c0e38
commit
df607bacdd
2 changed files with 29 additions and 12 deletions
|
|
@ -27,7 +27,7 @@ enum { magicMastSlaveConnectionHeader = 0x712baf04 };
|
|||
static const char* startMessage = "__ipc_st";
|
||||
static const char* killMessage = "__ipc_k_";
|
||||
static const char* pingMessage = "__ipc_p_";
|
||||
enum { specialMessageSize = 8 };
|
||||
enum { specialMessageSize = 8, defaultTimeoutMs = 8000 };
|
||||
|
||||
static String getCommandLinePrefix (const String& commandLineUniqueID)
|
||||
{
|
||||
|
|
@ -40,7 +40,7 @@ static String getCommandLinePrefix (const String& commandLineUniqueID)
|
|||
struct ChildProcessPingThread : public Thread,
|
||||
private AsyncUpdater
|
||||
{
|
||||
ChildProcessPingThread() : Thread ("IPC ping"), timeoutMs (8000)
|
||||
ChildProcessPingThread (int timeout) : Thread ("IPC ping"), timeoutMs (timeout)
|
||||
{
|
||||
pingReceived();
|
||||
}
|
||||
|
|
@ -84,8 +84,10 @@ private:
|
|||
struct ChildProcessMaster::Connection : public InterprocessConnection,
|
||||
private ChildProcessPingThread
|
||||
{
|
||||
Connection (ChildProcessMaster& m, const String& pipeName)
|
||||
: InterprocessConnection (false, magicMastSlaveConnectionHeader), owner (m)
|
||||
Connection (ChildProcessMaster& m, const String& pipeName, int timeout)
|
||||
: InterprocessConnection (false, magicMastSlaveConnectionHeader),
|
||||
ChildProcessPingThread (timeout),
|
||||
owner (m)
|
||||
{
|
||||
if (createPipe (pipeName, timeoutMs))
|
||||
startThread (4);
|
||||
|
|
@ -140,7 +142,7 @@ bool ChildProcessMaster::sendMessageToSlave (const MemoryBlock& mb)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool ChildProcessMaster::launchSlaveProcess (const File& executable, const String& commandLineUniqueID)
|
||||
bool ChildProcessMaster::launchSlaveProcess (const File& executable, const String& commandLineUniqueID, int timeoutMs)
|
||||
{
|
||||
connection = nullptr;
|
||||
jassert (childProcess.kill());
|
||||
|
|
@ -153,7 +155,7 @@ bool ChildProcessMaster::launchSlaveProcess (const File& executable, const Strin
|
|||
|
||||
if (childProcess.start (args))
|
||||
{
|
||||
connection = new Connection (*this, pipeName);
|
||||
connection = new Connection (*this, pipeName, timeoutMs <= 0 ? defaultTimeoutMs : timeoutMs);
|
||||
|
||||
if (connection->isConnected())
|
||||
{
|
||||
|
|
@ -171,8 +173,10 @@ bool ChildProcessMaster::launchSlaveProcess (const File& executable, const Strin
|
|||
struct ChildProcessSlave::Connection : public InterprocessConnection,
|
||||
private ChildProcessPingThread
|
||||
{
|
||||
Connection (ChildProcessSlave& p, const String& pipeName)
|
||||
: InterprocessConnection (false, magicMastSlaveConnectionHeader), owner (p)
|
||||
Connection (ChildProcessSlave& p, const String& pipeName, int timeout)
|
||||
: InterprocessConnection (false, magicMastSlaveConnectionHeader),
|
||||
ChildProcessPingThread (timeout),
|
||||
owner (p)
|
||||
{
|
||||
connectToPipe (pipeName, timeoutMs);
|
||||
startThread (4);
|
||||
|
|
@ -237,7 +241,8 @@ bool ChildProcessSlave::sendMessageToMaster (const MemoryBlock& mb)
|
|||
}
|
||||
|
||||
bool ChildProcessSlave::initialiseFromCommandLine (const String& commandLine,
|
||||
const String& commandLineUniqueID)
|
||||
const String& commandLineUniqueID,
|
||||
int timeoutMs)
|
||||
{
|
||||
String prefix (getCommandLinePrefix (commandLineUniqueID));
|
||||
|
||||
|
|
@ -248,7 +253,7 @@ bool ChildProcessSlave::initialiseFromCommandLine (const String& commandLine,
|
|||
|
||||
if (pipeName.isNotEmpty())
|
||||
{
|
||||
connection = new Connection (*this, pipeName);
|
||||
connection = new Connection (*this, pipeName, timeoutMs <= 0 ? defaultTimeoutMs : timeoutMs);
|
||||
|
||||
if (! connection->isConnected())
|
||||
connection = nullptr;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue