Better handling of shutdown state in client side.

This commit is contained in:
Stephane Letz 2013-01-31 13:01:17 +01:00
parent d9c1f2960d
commit 7ec46dbb46
8 changed files with 44 additions and 29 deletions

View File

@ -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();

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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()

View File

@ -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();

View File

@ -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:

View File

@ -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();