Skip to content

Commit

Permalink
review comments rework
Browse files Browse the repository at this point in the history
  • Loading branch information
sorgom committed Apr 2, 2024
1 parent 8ce9127 commit b76ebdf
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
9 changes: 9 additions & 0 deletions code/TCP_Srv_Base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ void TCP_Srv_Base::startThread(SOCKET clientSocket)
++mCnt;
++mNum;
std::thread(&TCP_Srv_Base::tm, this, clientSocket, mNum).detach();
displayThreads();
}

void TCP_Srv_Base::endOfThread()
Expand All @@ -200,5 +201,13 @@ void TCP_Srv_Base::endOfThread()
mNum = 0;
TRACE("--- no clients ---")
}
displayThreads();
}
}

void TCP_Srv_Base::displayThreads() const
{
#ifndef VERBOSE
cout << "threads:" << setw(6) << mCnt << '\r';
#endif
}
7 changes: 6 additions & 1 deletion code/TCP_Srv_Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ class TCP_Srv_Base
void run(INT32 argc, const CONST_C_STRING* argv);

protected:
// timeval seconds
constexpr static UINT32 tmSec = SELECT_MILLI_SECONDS / 1000;
// timeval microseconds
constexpr static UINT32 tmMic = (SELECT_MILLI_SECONDS % 1000) * 1000;
constexpr static UINT32 buffSize = READ_BUFFER_SIZE;
// (minimum) buffer size
constexpr static UINT32 buffSize = READ_BUFFER_SIZE < 4 ? 4 : READ_BUFFER_SIZE;
using Buffer = CHAR[buffSize];

// process received data
Expand All @@ -68,6 +71,8 @@ class TCP_Srv_Base
void startThread(SOCKET clientSocket);
// decrease thread count, reset thread number when count is 0
void endOfThread();
// display current number of threads
void displayThreads() const;
};

#endif // _H
5 changes: 3 additions & 2 deletions code/TCP_Srv_Echo.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ class TCP_Srv_Echo : public TCP_Srv_Base
public:
inline TCP_Srv_Echo() = default;
protected:
// simple implementation of process: echo received data
// trace received data if TRACE_ON is defined
// simple implementation of process:
// - echo received data
// - trace received data if VERBOSE is defined
void process(const SOCKET clientSocket, Buffer buff, size_t size, UINT32 nr) final;
};

Expand Down
2 changes: 1 addition & 1 deletion make/TCP_Srv_Echo.make
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ALL_LDFLAGS += $(LDFLAGS) -pthread

else ifeq ($(config),vsmall)
OBJDIR = obj/gcc/vsmall
DEFINES += -DDEBUG -DVERBOSE -DSELECT_MILLI_SECONDS=1000 -DREAD_BUFFER_SIZE=16
DEFINES += -DDEBUG -DVERBOSE -DSELECT_MILLI_SECONDS=1000 -DREAD_BUFFER_SIZE=8
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O0 -g -std=c++17 -pedantic-errors -Werror -Wall
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O0 -g -std=c++17 -pedantic-errors -Werror -Wall
ALL_LDFLAGS += $(LDFLAGS) -pthread
Expand Down
2 changes: 1 addition & 1 deletion make/howto_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $> make help
Usage: make [config=name] [target]

CONFIGURATIONS:
silent
prod
verbose
vsmall

Expand Down
5 changes: 2 additions & 3 deletions make/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
-- - no optimization
-- - vsmall:
-- - same as verbose
-- - but with small buffer sizes (16 bytes)
-- - but with small buffer sizes (8 bytes)
-- - and long select timeout (1 second)
-- ============================================================
-- created by Manfred Sorgo

workspace 'TCP_Srv_Echo'
configurations { 'prod', 'verbose', 'vsmall' }
language 'C++'
optimize 'On'

project 'TCP_Srv_Echo'
kind 'ConsoleApp'
Expand All @@ -40,7 +39,7 @@ workspace 'TCP_Srv_Echo'
defines {
'DEBUG', 'VERBOSE',
'SELECT_MILLI_SECONDS=1000',
'READ_BUFFER_SIZE=16'
'READ_BUFFER_SIZE=8'
}
symbols 'On'
optimize 'Off'
Expand Down

0 comments on commit b76ebdf

Please sign in to comment.