From 444e10acaf83cda5fc7f89768b5049ad2b79e2aa Mon Sep 17 00:00:00 2001 From: Chris Marsh Date: Mon, 17 Jul 2017 15:42:06 -0700 Subject: [PATCH] Don't need queue here --- src/rpc_connection.cpp | 26 ++++++++------------------ src/rpc_connection.h | 1 + 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/rpc_connection.cpp b/src/rpc_connection.cpp index 84c023a..09ad0fb 100644 --- a/src/rpc_connection.cpp +++ b/src/rpc_connection.cpp @@ -5,14 +5,6 @@ static const int RpcVersion = 1; static RpcConnection Instance; -static const size_t SendQueueSize = 4; -static RpcConnection::MessageFrame SendQueue[SendQueueSize]; -static std::atomic_uint SendQueueNext = 0; - -static RpcConnection::MessageFrame* NextSendFrame() { - auto index = (SendQueueNext++) % SendQueueSize; - return &SendQueue[index]; -} /*static*/ RpcConnection* RpcConnection::Create(const char* applicationId) { @@ -42,13 +34,12 @@ void RpcConnection::Open() } } - auto handshakeFrame = NextSendFrame(); - handshakeFrame->opcode = Opcode::Handshake; - char* json = handshakeFrame->message; + sendFrame.opcode = Opcode::Handshake; + char* json = sendFrame.message; JsonWriteHandshakeObj(json, RpcVersion, appId); - handshakeFrame->length = json - handshakeFrame->message; + sendFrame.length = json - sendFrame.message; - if (connection->Write(handshakeFrame, sizeof(MessageFrameHeader) + handshakeFrame->length)) { + if (connection->Write(&sendFrame, sizeof(MessageFrameHeader) + sendFrame.length)) { state = State::Connected; if (onConnect) { onConnect(); @@ -67,11 +58,10 @@ void RpcConnection::Close() void RpcConnection::Write(const void* data, size_t length) { - auto frame = NextSendFrame(); - frame->opcode = Opcode::Frame; - memcpy(frame->message, data, length); - frame->length = length; - if (!connection->Write(frame, sizeof(MessageFrameHeader) + length)) { + sendFrame.opcode = Opcode::Frame; + memcpy(sendFrame.message, data, length); + sendFrame.length = length; + if (!connection->Write(&sendFrame, sizeof(MessageFrameHeader) + length)) { Close(); } } diff --git a/src/rpc_connection.h b/src/rpc_connection.h index 5e761d0..d31f1c4 100644 --- a/src/rpc_connection.h +++ b/src/rpc_connection.h @@ -37,6 +37,7 @@ struct RpcConnection { char appId[64]{}; int lastErrorCode{0}; char lastErrorMessage[256]{}; + RpcConnection::MessageFrame sendFrame; static RpcConnection* Create(const char* applicationId); static void Destroy(RpcConnection*&);