Got it compiling and somewhat working, except post.
This commit is contained in:
parent
7ee13e87d2
commit
bcea21cf96
31
.vscode/launch.json
vendored
Normal file
31
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Debug",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"linux": {
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "gdb",
|
||||
"program": "${workspaceFolder}/output/main"
|
||||
},
|
||||
"osx": {
|
||||
"MIMode": "lldb",
|
||||
"miDebuggerPath": "lldb-mi",
|
||||
"program": "${workspaceFolder}/output/main"
|
||||
},
|
||||
"windows": {
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "gdb.exe",
|
||||
"program": "${workspaceFolder}/output/main.exe"
|
||||
},
|
||||
"preLaunchTask": "build"
|
||||
}
|
||||
]
|
||||
}
|
84
.vscode/tasks.json
vendored
Normal file
84
.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "build",
|
||||
"type": "shell",
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"windows": {
|
||||
"command": "powershell",
|
||||
"args": [
|
||||
"-c",
|
||||
"mingw32-make"
|
||||
]
|
||||
},
|
||||
"linux": {
|
||||
"command": "bash",
|
||||
"args": [
|
||||
"-c",
|
||||
"make"
|
||||
]
|
||||
},
|
||||
"osx": {
|
||||
"command": "bash",
|
||||
"args": [
|
||||
"-c",
|
||||
"make"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "build & run",
|
||||
"type": "shell",
|
||||
"windows": {
|
||||
"command": "powershell",
|
||||
"args": [
|
||||
"-c",
|
||||
"'mingw32-make run'"
|
||||
]
|
||||
},
|
||||
"linux": {
|
||||
"command": "bash",
|
||||
"args": [
|
||||
"-c",
|
||||
"'make run'"
|
||||
]
|
||||
},
|
||||
"osx": {
|
||||
"command": "bash",
|
||||
"args": [
|
||||
"-c",
|
||||
"'make run'"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "clean",
|
||||
"type": "shell",
|
||||
"windows": {
|
||||
"command": "powershell",
|
||||
"args": [
|
||||
"-c",
|
||||
"'mingw32-make clean'"
|
||||
]
|
||||
},
|
||||
"linux": {
|
||||
"command": "bash",
|
||||
"args": [
|
||||
"-c",
|
||||
"'make clean'"
|
||||
]
|
||||
},
|
||||
"osx": {
|
||||
"command": "bash",
|
||||
"args": [
|
||||
"-c",
|
||||
"'make clean'"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
91
Makefile
Normal file
91
Makefile
Normal file
@ -0,0 +1,91 @@
|
||||
#
|
||||
# 'make' build executable file 'main'
|
||||
# 'make clean' removes all .o and executable files
|
||||
#
|
||||
|
||||
# define the Cpp compiler to use
|
||||
CXX = g++
|
||||
|
||||
# define any compile-time flags
|
||||
CXXFLAGS := -std=c++17 -Wall -Wextra -g
|
||||
|
||||
# define library paths in addition to /usr/lib
|
||||
# if I wanted to include libraries not in /usr/lib I'd specify
|
||||
# their path using -Lpath, something like:
|
||||
LFLAGS =
|
||||
|
||||
# define output directory
|
||||
OUTPUT := output
|
||||
|
||||
# define source directory
|
||||
SRC := src
|
||||
|
||||
# define include directory
|
||||
INCLUDE := include
|
||||
|
||||
# define lib directory
|
||||
LIB := lib
|
||||
|
||||
ifeq ($(OS),Windows_NT)
|
||||
MAIN := main.exe
|
||||
SOURCEDIRS := $(SRC)
|
||||
INCLUDEDIRS := $(INCLUDE)
|
||||
LIBDIRS := $(LIB)
|
||||
FIXPATH = $(subst /,\,$1)
|
||||
RM := del /q /f
|
||||
MD := mkdir
|
||||
else
|
||||
MAIN := main
|
||||
SOURCEDIRS := $(shell find $(SRC) -type d)
|
||||
INCLUDEDIRS := $(shell find $(INCLUDE) -type d)
|
||||
LIBDIRS := $(shell find $(LIB) -type d)
|
||||
FIXPATH = $1
|
||||
RM = rm -f
|
||||
MD := mkdir -p
|
||||
endif
|
||||
|
||||
# define any directories containing header files other than /usr/include
|
||||
INCLUDES := $(patsubst %,-I%, $(INCLUDEDIRS:%/=%))
|
||||
|
||||
# define the C libs
|
||||
LIBS := $(patsubst %,-L%, $(LIBDIRS:%/=%))
|
||||
|
||||
# define the C source files
|
||||
SOURCES := $(wildcard $(patsubst %,%/*.cpp, $(SOURCEDIRS)))
|
||||
|
||||
# define the C object files
|
||||
OBJECTS := $(SOURCES:.cpp=.o)
|
||||
|
||||
#
|
||||
# The following part of the makefile is generic; it can be used to
|
||||
# build any executable just by changing the definitions above and by
|
||||
# deleting dependencies appended to the file from 'make depend'
|
||||
#
|
||||
|
||||
OUTPUTMAIN := $(call FIXPATH,$(OUTPUT)/$(MAIN))
|
||||
|
||||
all: $(OUTPUT) $(MAIN)
|
||||
@echo Executing 'all' complete!
|
||||
|
||||
$(OUTPUT):
|
||||
$(MD) $(OUTPUT)
|
||||
|
||||
$(MAIN): $(OBJECTS)
|
||||
$(CXX) $(CXXFLAGS) $(INCLUDES) -o $(OUTPUTMAIN) $(OBJECTS) $(LFLAGS) $(LIBS)
|
||||
|
||||
# this is a suffix replacement rule for building .o's from .c's
|
||||
# it uses automatic variables $<: the name of the prerequisite of
|
||||
# the rule(a .c file) and $@: the name of the target of the rule (a .o file)
|
||||
# (see the gnu make manual section about automatic variables)
|
||||
.cpp.o:
|
||||
$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
$(RM) $(OUTPUTMAIN)
|
||||
$(RM) $(call FIXPATH,$(OBJECTS))
|
||||
@echo Cleanup complete!
|
||||
|
||||
run: all
|
||||
./$(OUTPUTMAIN)
|
||||
@echo Executing 'run: all' complete!
|
@ -23,13 +23,11 @@ namespace core {
|
||||
}
|
||||
|
||||
void TCPServer::onDataReceived(std::string data) {
|
||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "entering TCPServer::onDataReceived socket " << getDescriptor() << ".";
|
||||
lock.lock();
|
||||
TCPSession *session = accept();
|
||||
if(session)
|
||||
sessions.push_back(session);
|
||||
sessions.push_back(session);
|
||||
lock.unlock();
|
||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "Leaving TCPServer::onDataReceived socket " << getDescriptor() << ".";
|
||||
}
|
||||
|
||||
TCPSession * TCPServer::accept() {
|
||||
|
@ -33,46 +33,41 @@ namespace core {
|
||||
|
||||
void TCPSession::onDataReceived(char *data, int len) {
|
||||
if(len > 0) {
|
||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize + len);
|
||||
memcpy(lineBuffer + lineBufferSize, data, len);
|
||||
lineBufferSize += len;
|
||||
while(lineBufferSize > 0) {
|
||||
switch(mode) {
|
||||
case LINE:
|
||||
lineLength = strcspn(lineBuffer, "\r\n");
|
||||
if(lineLength == lineBufferSize)
|
||||
break;
|
||||
onLineReceived(std::string(lineBuffer, lineLength));
|
||||
if(lineBuffer[lineLength] == '\r')
|
||||
++lineLength;
|
||||
if(lineBuffer[lineLength] == '\n')
|
||||
++lineLength;
|
||||
lineBufferSize -= lineLength;
|
||||
if(lineBufferSize > 0)
|
||||
memmove(lineBuffer, lineBuffer + lineLength, lineBufferSize);
|
||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
|
||||
break;
|
||||
case BLOCK:
|
||||
if(lineBufferSize >= blockLength) {
|
||||
onBlockReceived(std::string(lineBuffer, blockLength));
|
||||
lineBufferSize -= blockLength;
|
||||
if(lineBufferSize > 0)
|
||||
memmove(lineBuffer, lineBuffer + blockLength, lineBufferSize);
|
||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize + len);
|
||||
memcpy(lineBuffer + lineBufferSize, data, len);
|
||||
lineBufferSize += len;
|
||||
while(lineBufferSize > 0) {
|
||||
if(blockSize == 0) {
|
||||
lineLength = strcspn(lineBuffer, "\r\n");
|
||||
if(lineLength == lineBufferSize)
|
||||
break;
|
||||
onLineReceived(std::string(lineBuffer, lineLength));
|
||||
if(lineBuffer[lineLength] == '\r')
|
||||
++lineLength;
|
||||
if(lineBuffer[lineLength] == '\n')
|
||||
++lineLength;
|
||||
lineBufferSize -= lineLength;
|
||||
if(lineBufferSize > 0)
|
||||
memmove(lineBuffer, lineBuffer + lineLength, lineBufferSize);
|
||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
|
||||
} else {
|
||||
if(lineBufferSize >= blockLength) {
|
||||
onBlockReceived(std::string(lineBuffer, blockLength));
|
||||
lineBufferSize -= blockLength;
|
||||
if(lineBufferSize > 0)
|
||||
memmove(lineBuffer, lineBuffer + blockLength, lineBufferSize);
|
||||
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TCPSession::setMode(core::Mode mode, int blockSize) {
|
||||
this->mode = mode;
|
||||
void TCPSession::setBlockSize(int blockSize) {
|
||||
this->blockSize = blockSize;
|
||||
}
|
||||
|
||||
void TCPSession::onLineReceived(std::string line) {
|
||||
coreutils::Log(coreutils::LOG_DEBUG_3) << "[" << line << "]";
|
||||
protocol(line);
|
||||
send();
|
||||
if(term)
|
||||
|
13
TCPSession.h
13
TCPSession.h
@ -7,7 +7,6 @@
|
||||
namespace core {
|
||||
|
||||
class Command;
|
||||
enum Mode {LINE, BLOCK, PACKET};
|
||||
class TCPServer;
|
||||
|
||||
///
|
||||
@ -137,13 +136,12 @@ namespace core {
|
||||
virtual void protocol(std::string data);
|
||||
|
||||
///
|
||||
/// Use the setMode method to set the receiving mode for the data on this socket.
|
||||
/// Data can be received in LINE mode, which will receive data from the socket one
|
||||
/// line at a time, or BLOCK mode where a certain specified data block is received
|
||||
/// before calling the onBlockReceived method.
|
||||
/// Use setBlockSize to set the amount of data that should be read at once from the
|
||||
/// session data buffer.
|
||||
/// If this value is set to 0 then the data will be retrieved
|
||||
///
|
||||
|
||||
void setMode(core::Mode mode, int size = 0);
|
||||
void setBlockSize(int size = 0);
|
||||
|
||||
private:
|
||||
char *lineBuffer = NULL;
|
||||
@ -152,8 +150,7 @@ namespace core {
|
||||
int blockLength = 0;
|
||||
std::mutex mtx;
|
||||
bool term = false;
|
||||
core::Mode mode = LINE;
|
||||
int blockSize;
|
||||
int blockSize = 0;
|
||||
|
||||
};
|
||||
|
||||
|
@ -30,7 +30,7 @@ namespace core {
|
||||
IPAddress ipAddress;
|
||||
|
||||
///
|
||||
/// The output method is called by a socket session (BMASession) and
|
||||
/// The output method is called by a socket session (TCPSession) and
|
||||
/// will output the detail information for the client socket. When extending
|
||||
/// BMATCPSocket or BMASession you can override the method to add attributes
|
||||
/// to the list.
|
||||
|
BIN
output/main
Executable file
BIN
output/main
Executable file
Binary file not shown.
6
src/main.cpp
Normal file
6
src/main.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
std::cout << "Hello world!" << std::endl;
|
||||
}
|
38
src/workspace.code-workspace
Normal file
38
src/workspace.code-workspace
Normal file
@ -0,0 +1,38 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "../../CoreUtils"
|
||||
},
|
||||
{
|
||||
"path": ".."
|
||||
},
|
||||
{
|
||||
"path": "../../HTTPServer"
|
||||
}
|
||||
],
|
||||
"settings": {},
|
||||
"launch": {
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "(gdb) Launch",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "/home/barant/Development/HTTPServer/HTTPServer",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "/home/barant/Development/HTTPServer/",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user