From 177bc602af9779ccdfc5069154b384dc22a06f7f Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Tue, 20 Oct 2020 10:53:06 -0700 Subject: [PATCH] Working on block receive capability. --- TCPSession.cpp | 4 ++-- TCPSession.h | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/TCPSession.cpp b/TCPSession.cpp index 0967014..6239251 100644 --- a/TCPSession.cpp +++ b/TCPSession.cpp @@ -39,7 +39,7 @@ namespace core { while(lineBufferSize > 0) { switch(mode) { case LINE: - int lineLength = strcspn(lineBuffer, "\r\n"); + lineLength = strcspn(lineBuffer, "\r\n"); if(lineLength == lineBufferSize) break; onLineReceived(std::string(lineBuffer, lineLength)); @@ -66,7 +66,7 @@ namespace core { } } - void setMode(Mode mode, int blockSize = 0) { + void TCPSession::setMode(core::Mode mode, int blockSize) { this->mode = mode; this->blockSize = blockSize; } diff --git a/TCPSession.h b/TCPSession.h index 1f4ae73..00c63ca 100644 --- a/TCPSession.h +++ b/TCPSession.h @@ -1,5 +1,5 @@ #ifndef __Session_h__ -#define __Session_h__ +# define __Session_h__ #include "TCPSocket.h" #include "SessionFilter.h" @@ -7,6 +7,7 @@ namespace core { class Command; + enum Mode {LINE, BLOCK}; class TCPServer; @@ -59,7 +60,7 @@ namespace core { /// Use this sendToAll method to output the contents of the out stream /// to all the connections on the server excluding the sender session. /// - + void sendToAll(); /// @@ -82,8 +83,13 @@ namespace core { TCPServer &server; - enum Mode {LINE, BLOCK}; + /// + /// Set this value to control the next read event coming + /// from this socket. + /// +// enum Mode {LINE, BLOCK}; + protected: /// @@ -145,14 +151,16 @@ namespace core { /// before calling the onBlockReceived method. /// - void setMode(Mode mode, int size = 0); + void setMode(core::Mode mode, int size = 0); private: char *lineBuffer = NULL; int lineBufferSize = 0; + int lineLength = 0; + int blockLength = 0; std::mutex mtx; bool term = false; - enum Mode mode = LINE; + core::Mode mode = LINE; int blockSize; };