Working on block receive capability.
This commit is contained in:
parent
58dfd063f3
commit
177bc602af
@ -39,7 +39,7 @@ namespace core {
|
|||||||
while(lineBufferSize > 0) {
|
while(lineBufferSize > 0) {
|
||||||
switch(mode) {
|
switch(mode) {
|
||||||
case LINE:
|
case LINE:
|
||||||
int lineLength = strcspn(lineBuffer, "\r\n");
|
lineLength = strcspn(lineBuffer, "\r\n");
|
||||||
if(lineLength == lineBufferSize)
|
if(lineLength == lineBufferSize)
|
||||||
break;
|
break;
|
||||||
onLineReceived(std::string(lineBuffer, lineLength));
|
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->mode = mode;
|
||||||
this->blockSize = blockSize;
|
this->blockSize = blockSize;
|
||||||
}
|
}
|
||||||
|
16
TCPSession.h
16
TCPSession.h
@ -1,5 +1,5 @@
|
|||||||
#ifndef __Session_h__
|
#ifndef __Session_h__
|
||||||
#define __Session_h__
|
# define __Session_h__
|
||||||
|
|
||||||
#include "TCPSocket.h"
|
#include "TCPSocket.h"
|
||||||
#include "SessionFilter.h"
|
#include "SessionFilter.h"
|
||||||
@ -7,6 +7,7 @@
|
|||||||
namespace core {
|
namespace core {
|
||||||
|
|
||||||
class Command;
|
class Command;
|
||||||
|
enum Mode {LINE, BLOCK};
|
||||||
|
|
||||||
class TCPServer;
|
class TCPServer;
|
||||||
|
|
||||||
@ -82,7 +83,12 @@ namespace core {
|
|||||||
|
|
||||||
TCPServer &server;
|
TCPServer &server;
|
||||||
|
|
||||||
enum Mode {LINE, BLOCK};
|
///
|
||||||
|
/// Set this value to control the next read event coming
|
||||||
|
/// from this socket.
|
||||||
|
///
|
||||||
|
|
||||||
|
// enum Mode {LINE, BLOCK};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@ -145,14 +151,16 @@ namespace core {
|
|||||||
/// before calling the onBlockReceived method.
|
/// before calling the onBlockReceived method.
|
||||||
///
|
///
|
||||||
|
|
||||||
void setMode(Mode mode, int size = 0);
|
void setMode(core::Mode mode, int size = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char *lineBuffer = NULL;
|
char *lineBuffer = NULL;
|
||||||
int lineBufferSize = 0;
|
int lineBufferSize = 0;
|
||||||
|
int lineLength = 0;
|
||||||
|
int blockLength = 0;
|
||||||
std::mutex mtx;
|
std::mutex mtx;
|
||||||
bool term = false;
|
bool term = false;
|
||||||
enum Mode mode = LINE;
|
core::Mode mode = LINE;
|
||||||
int blockSize;
|
int blockSize;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user