diff --git a/common/JackClient.cpp b/common/JackClient.cpp index 297f5340..70e7f7aa 100644 --- a/common/JackClient.cpp +++ b/common/JackClient.cpp @@ -109,15 +109,12 @@ int JackClient::Close() int result = 0; Deactivate(); - fChannel->Stop(); // Channels is stopped first to avoid receiving notifications while closing - - // Request close only if server is still running - if (JackGlobals::fServerRunning) { - fChannel->ClientClose(GetClientControl()->fRefNum, &result); - } else { - jack_log("JackClient::Close server is shutdown"); - } - + + // Channels is stopped first to avoid receiving notifications while closing + fChannel->Stop(); + // Then close client + fChannel->ClientClose(GetClientControl()->fRefNum, &result); + fChannel->Close(); assert(JackGlobals::fSynchroMutex); JackGlobals::fSynchroMutex->Lock(); diff --git a/common/JackEngine.cpp b/common/JackEngine.cpp index dece3523..5f895785 100644 --- a/common/JackEngine.cpp +++ b/common/JackEngine.cpp @@ -831,16 +831,12 @@ int JackEngine::ClientDeactivate(int refnum) void JackEngine::ClientKill(int refnum) { - if (fClientTable[refnum]) { - jack_log("JackEngine::ClientKill ref = %ld", refnum); - if (ClientDeactivate(refnum) < 0) { - jack_error("JackEngine::ClientKill ref = %ld cannot be removed from the graph !!", refnum); - } - if (ClientExternalClose(refnum) < 0) { - jack_error("JackEngine::ClientKill ref = %ld cannot be closed", refnum); - } - } else { - jack_log("JackEngine::ClientKill ref = %ld probably already killed...", refnum); + jack_log("JackEngine::ClientKill ref = %ld", refnum); + if (ClientDeactivate(refnum) < 0) { + jack_error("JackEngine::ClientKill ref = %ld cannot be removed from the graph !!", refnum); + } + if (ClientExternalClose(refnum) < 0) { + jack_error("JackEngine::ClientKill ref = %ld cannot be closed", refnum); } } diff --git a/common/JackGenericClientChannel.cpp b/common/JackGenericClientChannel.cpp index 2cf2a26c..df7b038f 100644 --- a/common/JackGenericClientChannel.cpp +++ b/common/JackGenericClientChannel.cpp @@ -53,6 +53,12 @@ void JackGenericClientChannel::ServerSyncCall(JackRequest* req, JackResult* res, return; } + if (!JackGlobals::fServerRunning) { + jack_error("Server is not running"); + *result = -1; + return; + } + if (req->Write(fRequest) < 0) { jack_error("Could not write request type = %ld", req->fType); *result = -1; @@ -77,6 +83,12 @@ void JackGenericClientChannel::ServerAsyncCall(JackRequest* req, JackResult* res return; } + if (!JackGlobals::fServerRunning) { + jack_error("Server is not running"); + *result = -1; + return; + } + if (req->Write(fRequest) < 0) { jack_error("Could not write request type = %ld", req->fType); *result = -1; diff --git a/common/JackLibClient.cpp b/common/JackLibClient.cpp index a02175dd..2bbd7f7f 100644 --- a/common/JackLibClient.cpp +++ b/common/JackLibClient.cpp @@ -86,7 +86,7 @@ int JackLibClient::Open(const char* server_name, const char* name, int uuid, jac int shared_engine, shared_client, shared_graph, result; bool res; jack_log("JackLibClient::Open name = %s", name); - + if (strlen(name) >= JACK_CLIENT_NAME_SIZE) { jack_error("\"%s\" is too long to be used as a JACK client name.\n" "Please use %lu characters or less", @@ -141,7 +141,6 @@ int JackLibClient::Open(const char* server_name, const char* name, int uuid, jac } JackGlobals::fClientTable[GetClientControl()->fRefNum] = this; - JackGlobals::fServerRunning = true; SetClockSource(GetEngineControl()->fClockSource); jack_log("JackLibClient::Open name = %s refnum = %ld", name_res, GetClientControl()->fRefNum); return 0; diff --git a/posix/JackSocketClientChannel.cpp b/posix/JackSocketClientChannel.cpp index bb3f9c69..e8506e75 100644 --- a/posix/JackSocketClientChannel.cpp +++ b/posix/JackSocketClientChannel.cpp @@ -39,15 +39,21 @@ JackSocketClientChannel::~JackSocketClientChannel() delete fNotificationSocket; } -int JackSocketClientChannel::Open(const char* server_name, const char* name, int uuid, char* name_res, JackClient* obj, jack_options_t options, jack_status_t* status) +int JackSocketClientChannel::Open(const char* server_name, const char* name, int uuid, char* name_res, JackClient* client, jack_options_t options, jack_status_t* status) { int result = 0; jack_log("JackSocketClientChannel::Open name = %s", name); + + // Before any server/client call + fClient = client; if (fRequest->Connect(jack_server_dir, server_name, 0) < 0) { jack_error("Cannot connect to server socket"); goto error; } + + // OK so server is there... + JackGlobals::fServerRunning = true; // Check name in server ClientCheck(name, uuid, name_res, JACK_PROTOCOL_VERSION, (int)options, (int*)status, &result, true); @@ -65,8 +71,7 @@ int JackSocketClientChannel::Open(const char* server_name, const char* name, int jack_error("Cannot bind socket"); goto error; } - - fClient = obj; + return 0; error: @@ -79,8 +84,9 @@ void JackSocketClientChannel::Close() { fRequest->Close(); fNotificationListenSocket.Close(); - if (fNotificationSocket) + if (fNotificationSocket) { fNotificationSocket->Close(); + } } int JackSocketClientChannel::Start() diff --git a/posix/JackSocketClientChannel.h b/posix/JackSocketClientChannel.h index a96684d0..ff753d20 100644 --- a/posix/JackSocketClientChannel.h +++ b/posix/JackSocketClientChannel.h @@ -49,7 +49,7 @@ class JackSocketClientChannel : public JackGenericClientChannel, public JackRunn JackSocketClientChannel(); virtual ~JackSocketClientChannel(); - int Open(const char* server_name, const char* name, int uuid, char* name_res, JackClient* obj, jack_options_t options, jack_status_t* status); + int Open(const char* server_name, const char* name, int uuid, char* name_res, JackClient* client, jack_options_t options, jack_status_t* status); void Close(); int Start(); diff --git a/windows/JackWinNamedPipeClientChannel.cpp b/windows/JackWinNamedPipeClientChannel.cpp index ec327976..c47a389f 100644 --- a/windows/JackWinNamedPipeClientChannel.cpp +++ b/windows/JackWinNamedPipeClientChannel.cpp @@ -38,7 +38,7 @@ JackWinNamedPipeClientChannel::~JackWinNamedPipeClientChannel() delete fRequest; } -int JackWinNamedPipeClientChannel::Open(const char* server_name, const char* name, int uuid, char* name_res, JackClient* obj, jack_options_t options, jack_status_t* status) +int JackWinNamedPipeClientChannel::Open(const char* server_name, const char* name, int uuid, char* name_res, JackClient* client, jack_options_t options, jack_status_t* status) { int result = 0; jack_log("JackWinNamedPipeClientChannel::Open name = %s", name); @@ -50,11 +50,17 @@ int JackWinNamedPipeClientChannel::Open(const char* server_name, const char* nam goto error; } */ + + // Before any server/client call + fClient = client; if (fRequest->Connect(jack_server_dir, server_name, 0) < 0) { jack_error("Cannot connect to server pipe"); goto error; } + + // OK so server is there... + JackGlobals::fServerRunning = true; // Check name in server ClientCheck(name, uuid, name_res, JACK_PROTOCOL_VERSION, (int)options, (int*)status, &result, true); @@ -72,7 +78,6 @@ int JackWinNamedPipeClientChannel::Open(const char* server_name, const char* nam goto error; } - fClient = obj; return 0; error: diff --git a/windows/JackWinNamedPipeClientChannel.h b/windows/JackWinNamedPipeClientChannel.h index 8660029b..6542399d 100644 --- a/windows/JackWinNamedPipeClientChannel.h +++ b/windows/JackWinNamedPipeClientChannel.h @@ -49,7 +49,7 @@ class JackWinNamedPipeClientChannel : public JackGenericClientChannel, public Ja JackWinNamedPipeClientChannel(); virtual ~JackWinNamedPipeClientChannel(); - int Open(const char* server_name, const char* name, int uuid, char* name_res, JackClient* obj, jack_options_t options, jack_status_t* status); + int Open(const char* server_name, const char* name, int uuid, char* name_res, JackClient* client, jack_options_t options, jack_status_t* status); void Close(); int Start();