Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Som devel #3

Open
wants to merge 57 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
986f67d
start of basics collection
sorgom Mar 28, 2024
e11a1f2
start of basics collection
sorgom Mar 28, 2024
9138767
basics collection
sorgom Mar 28, 2024
5eb23c3
py: echo client & server
sorgom Mar 29, 2024
03f6cb5
interim
sorgom Mar 29, 2024
933830f
interim
sorgom Mar 29, 2024
1159068
interim
sorgom Mar 29, 2024
f6415f4
interim
sorgom Mar 29, 2024
39ae9d6
interim
sorgom Mar 30, 2024
e16f8bf
rework TCP_Srv_Base
sorgom Mar 30, 2024
4f5266f
rework TCP_Srv_Base
sorgom Mar 30, 2024
5880ace
rework TCP_Srv_Base
sorgom Mar 30, 2024
4c81fe1
interim / naming
sorgom Mar 31, 2024
939f23e
interim / naming
sorgom Mar 31, 2024
8e3ee2f
progress, ready for cleanup
sorgom Mar 31, 2024
a2d0946
removed dev samples
sorgom Mar 31, 2024
1504242
reduction to required
sorgom Mar 31, 2024
6b0b60a
removed simple python echo client
sorgom Mar 31, 2024
8160013
established python prallel echo client
sorgom Mar 31, 2024
624a1bf
added comments
sorgom Mar 31, 2024
a30d3e3
ready for CI
sorgom Apr 1, 2024
5662b60
substantial rework after review
sorgom Apr 1, 2024
00b0b1c
CI
sorgom Apr 1, 2024
ca40c04
configurations & wording
sorgom Apr 1, 2024
5ba2cf6
syntax check CI
sorgom Apr 1, 2024
e8d318f
syntax check CI
sorgom Apr 1, 2024
8e6a363
syntax check CI
sorgom Apr 1, 2024
f1c4f90
syntax check CI
sorgom Apr 1, 2024
28725f9
syntax check CI
sorgom Apr 1, 2024
e08a62e
syntax check CI
sorgom Apr 1, 2024
9af3e52
review comments rework
sorgom Apr 2, 2024
fb394b3
review comments rework
sorgom Apr 2, 2024
80b8530
review comments rework
sorgom Apr 2, 2024
8ce9127
review comments rework
sorgom Apr 2, 2024
b76ebdf
review comments rework
sorgom Apr 2, 2024
e5fc5ea
review comments rework
sorgom Apr 3, 2024
baa3aa1
review comments rework
sorgom Apr 3, 2024
1fb1796
review comments rework
sorgom Apr 3, 2024
639da32
CI error fixed
sorgom Apr 3, 2024
ed5b27e
CI error fixed
sorgom Apr 3, 2024
fc5f57e
review comments rework, elimination of macros, Trace
sorgom Apr 4, 2024
79c8e5a
just for the sake of it: ask ChatGPT
sorgom Apr 4, 2024
714130a
just for the sake of it: ask ChatGPT
sorgom Apr 4, 2024
1ad6954
review comments rework, correction select
sorgom Apr 5, 2024
0e152bd
build, Trace
sorgom Apr 6, 2024
763d89c
better tracing; removed cleanup
sorgom Apr 6, 2024
2212327
build, GPT for gcc & VS
sorgom Apr 7, 2024
e6a927a
review rework
sorgom Apr 7, 2024
5f71bfa
review rework
sorgom Apr 7, 2024
6d1f95f
review rework
sorgom Apr 7, 2024
c1647ff
integrated ChatGPT solution
sorgom Apr 7, 2024
1627c0c
review rework; documentation
sorgom Apr 8, 2024
658841e
reworked issue #2
sorgom Apr 8, 2024
c63c09c
min mod
sorgom Apr 8, 2024
d1acd63
added exec
sorgom Apr 13, 2024
5384dfb
test mode
sorgom Apr 23, 2024
83f5c0a
test mode
sorgom Apr 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
- name: prepare build
run: chmod 755 make/build.sh
- name: build
run: make/build.sh -c
run: make/build.sh -cr prod test
75 changes: 40 additions & 35 deletions code/TCP_Srv_Base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ void TCP_Srv_Base::run(const INT32 argc, const CONST_C_STRING* const argv)
if (argc > 1)
{
UINT16 port = defPort;
regex rxPort {"^\\d{2,5}$"};
regex rxHelp {"^-[hH]$"};
const regex rxPort {"^\\d{2,5}$"};
const regex rxHelp {"^-[hH]$"};
const regex rxTest {"^test$", std::regex_constants::icase};
bool cont = true;
for (INT32 n = 1; cont and n < argc; ++n)
{
Expand All @@ -45,6 +46,7 @@ void TCP_Srv_Base::run(const INT32 argc, const CONST_C_STRING* const argv)
for (INT32 n = 1; cont and n < argc; ++n)
{
if (regex_match(argv[n], rxPort)) port = static_cast<UINT16>(atoi(argv[n]));
else if (regex_match(argv[n], rxTest)) mTest = true;
else cont = handleArg(argv[n]);
}
if (cont) run(port);
Expand Down Expand Up @@ -113,49 +115,52 @@ void TCP_Srv_Base::run(const UINT16 port)
displayThreads();
}

// select and other tasks loop
while (ok)
if (not mTest)
{

// select and accept loop
bool clients = false;
do
// select and other tasks loop
while (ok)
{
clients = false;
// select
fd_set lset;
FD_ZERO(&lset);
FD_SET(listenSocket, &lset);
timeval tv { tmSec, tmMic};

if (select(listenSocket + 1, &lset, nullptr, nullptr, &tv) < 0)
{
cerr << "ERR listen select" << endl;
ok = false;
}


// accept to new client socket if listen socket is set
else if (FD_ISSET(listenSocket, &lset))
// select and accept loop
bool clients = false;
do
{
SOCKET clientSocket = accept(listenSocket, nullptr, nullptr);

if (clientSocket < 0)
clients = false;
// select
fd_set lset;
FD_ZERO(&lset);
FD_SET(listenSocket, &lset);
timeval tv { tmSec, tmMic};

if (select(listenSocket + 1, &lset, nullptr, nullptr, &tv) < 0)
{
cerr << "ERR accept" << endl;
cerr << "ERR listen select" << endl;
ok = false;
}
// start thread with client socket
else


// accept to new client socket if listen socket is set
else if (FD_ISSET(listenSocket, &lset))
{
startThread(clientSocket);
clients = true;
SOCKET clientSocket = accept(listenSocket, nullptr, nullptr);

if (clientSocket < 0)
{
cerr << "ERR accept" << endl;
ok = false;
}
// start thread with client socket
else
{
startThread(clientSocket);
clients = true;
}
}
}
} while (clients);
} while (clients);

// other tasks
otherTasks();
// other tasks
otherTasks();
}
}
// only reached in case of error: clean up
if (listenSocket >= 0)
Expand Down
6 changes: 4 additions & 2 deletions code/TCP_Srv_Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,18 @@ class TCP_Srv_Base
private:
// default port
constexpr static UINT16 defPort = 8080;
// client thread method
void handleClient(SOCKET clientSocket, UINT32 nr);
// thread count
UINT32 mCnt = 0;
// thread number
UINT32 mNum = 0;
// mutex for thread count and number
std::mutex mMtxStat;
// just bind test
bool mTest = false;
// start thread with increased thread number and count
void startThread(SOCKET clientSocket);
// client thread method
void handleClient(SOCKET clientSocket, UINT32 nr);
// decrease thread count, reset thread number when count is 0
void endOfThread();
// display current number of threads
Expand Down
4 changes: 2 additions & 2 deletions code/TCP_Srv_Echo_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ int main(const INT32 argc, const CONST_C_STRING* const argv)
{
TCP_Srv_Echo srv;
srv.run(argc, argv);
// only reached in case of failure
return 1;
// reached in case of test mode
return 0;
}
4 changes: 2 additions & 2 deletions make/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ getcfgs()

help()
{
echo "Usage: $(basename $0) options [port] [locale]"
echo "Usage: $(basename $0) [options] [port] [locale]"
echo "options:"
echo "-c clean ignored artifacts before"
echo "-r <config> run binary with [port] [locale]"
Expand Down Expand Up @@ -106,4 +106,4 @@ fi
echo ""
echo "starting $bin $*"
echo ""
$bin $*
exec $bin $*
2 changes: 1 addition & 1 deletion make/howto_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ TCP_Srv\make> premake5 vs2019
````
### 2) build executables in VS
- open solution (TCP_Srv/make/EchoSrv.sln)
- select a configuration (see also header of premake5.lua)
- select a configuration (see also header of [premake5.lua](premake5.lua))
- build (and run)

### 3) VS keyboard shortcuts
Expand Down
Loading