Working on block receive capability.
This commit is contained in:
parent
58dfd063f3
commit
177bc602af
@ -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;
|
||||
}
|
||||
|
18
TCPSession.h
18
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;
|
||||
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user