Working on block receive capability.

This commit is contained in:
Brad Arant 2020-10-20 10:53:06 -07:00
parent 58dfd063f3
commit 177bc602af
2 changed files with 15 additions and 7 deletions

View File

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

View File

@ -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;
@ -82,7 +83,12 @@ 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;
};