From 045c0544f2c25ca2f8cde3c8ff0ff88506e32f1a Mon Sep 17 00:00:00 2001 From: sletz Date: Thu, 12 Jan 2012 17:20:47 +0000 Subject: [PATCH] Change JackRequestDecoder for Windows. git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4694 0c269be4-1314-0410-8aa9-9f06e86f4224 --- common/JackRequestDecoder.cpp | 24 ++++++++++------------- common/JackRequestDecoder.h | 2 +- posix/JackSocketServerChannel.cpp | 10 ++++++++-- windows/JackWinNamedPipeServerChannel.cpp | 18 +++++++++++------ 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/common/JackRequestDecoder.cpp b/common/JackRequestDecoder.cpp index 4bd9f37e..5ab1c67c 100644 --- a/common/JackRequestDecoder.cpp +++ b/common/JackRequestDecoder.cpp @@ -37,17 +37,12 @@ JackRequestDecoder::JackRequestDecoder(JackServer* server, JackClientHandlerInte JackRequestDecoder::~JackRequestDecoder() {} -bool JackRequestDecoder::HandleRequest(detail::JackChannelTransactionInterface* socket) +void JackRequestDecoder::HandleRequest(detail::JackChannelTransactionInterface* socket, int type_aux) { - // Read header - JackRequest header; - if (header.Read(socket) < 0) { - jack_log("HandleRequest: cannot read header"); - return false; - } - + JackRequest::RequestType type = (JackRequest::RequestType)type_aux; + // Read data - switch (header.fType) { + switch (type) { case JackRequest::kClientCheck: { jack_log("JackRequest::ClientCheck"); @@ -58,8 +53,11 @@ bool JackRequestDecoder::HandleRequest(detail::JackChannelTransactionInterface* if (res.Write(socket) < 0) jack_error("JackRequest::ClientCheck write error name = %s", req.fName); // Atomic ClientCheck followed by ClientOpen on same socket - if (req.fOpen) - HandleRequest(socket); + if (req.fOpen) { + JackRequest header; + header.Read(socket); + HandleRequest(socket, header.fType); + } break; } @@ -369,11 +367,9 @@ bool JackRequestDecoder::HandleRequest(detail::JackChannelTransactionInterface* } default: - jack_error("Unknown request %ld", header.fType); + jack_error("Unknown request %ld", type); break; } - - return true; } } // end of namespace diff --git a/common/JackRequestDecoder.h b/common/JackRequestDecoder.h index 23fc3a1a..bee7b68d 100644 --- a/common/JackRequestDecoder.h +++ b/common/JackRequestDecoder.h @@ -52,7 +52,7 @@ class JackRequestDecoder JackRequestDecoder(JackServer* server, JackClientHandlerInterface* handler); virtual ~JackRequestDecoder(); - bool HandleRequest(detail::JackChannelTransactionInterface* socket); + void HandleRequest(detail::JackChannelTransactionInterface* socket, int type); }; } // end of namespace diff --git a/posix/JackSocketServerChannel.cpp b/posix/JackSocketServerChannel.cpp index 7b081968..e2285b95 100644 --- a/posix/JackSocketServerChannel.cpp +++ b/posix/JackSocketServerChannel.cpp @@ -236,9 +236,15 @@ bool JackSocketServerChannel::Execute() jack_log("Poll client error err = %s", strerror(errno)); ClientKill(fd); } else if (fPollTable[i].revents & POLLIN) { - if (!fDecoder->HandleRequest(fSocketTable[fd].second)) { - jack_log("Could not handle external client request"); + // Read header + JackClientSocket* socket = fSocketTable[fd].second; + JackRequest header; + if (header.Read(socket) < 0) { + jack_log("HandleRequest: cannot read header"); ClientKill(fd); + return false; + } else { + fDecoder->HandleRequest(socket, header.fType); } } } diff --git a/windows/JackWinNamedPipeServerChannel.cpp b/windows/JackWinNamedPipeServerChannel.cpp index dbc3d60c..c2b74432 100644 --- a/windows/JackWinNamedPipeServerChannel.cpp +++ b/windows/JackWinNamedPipeServerChannel.cpp @@ -88,18 +88,24 @@ bool JackClientPipeThread::Execute() try{ jack_log("JackClientPipeThread::Execute"); + JackRequest header; + if (header.Read(socket) < 0) { + jack_log("HandleRequest: cannot read header"); + ClientKill(fd); + return false; + } + // Lock the global mutex if (WaitForSingleObject(fMutex, INFINITE) == WAIT_FAILED) { jack_error("JackClientPipeThread::HandleRequest: mutex wait error"); } - - bool res = fDecoder->HandleRequest(fPipe); - if (!res) { - ClientKill(); - } + + fDecoder->HandleRequest(fPipe, header.fType); // Unlock the global mutex - ReleaseMutex(fMutex); + if (!ReleaseMutex(fMutex)) { + jack_error("JackClientPipeThread::HandleRequest: mutex release error"); + } return res; } catch (JackQuitException& e) {