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

Rewrite service code #8

Merged
merged 8 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ jobs:

- name: Test
working-directory: ${{ runner.workspace }}/build
run: ctest --timeout 30 -C ${{ matrix.build-type }}
run: ctest --timeout 30 -j 4 -C ${{ matrix.build-type }}
2 changes: 1 addition & 1 deletion .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ jobs:

- name: Test
working-directory: ${{ runner.workspace }}/build
run: ctest --timeout 30 -C ${{ matrix.build-type }}
run: ctest --timeout 30 -j 4 -C ${{ matrix.build-type }}
16 changes: 8 additions & 8 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "--timeout 30"
"ctestCommandArgs": "--timeout 30 -j 4"
},
{
"name": "2. Windows x86 Release",
Expand All @@ -22,7 +22,7 @@
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "--timeout 30"
"ctestCommandArgs": "--timeout 30 -j 4"
},
{
"name": "3. Windows x64 Debug",
Expand All @@ -34,7 +34,7 @@
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "--timeout 30"
"ctestCommandArgs": "--timeout 30 -j 4"
},
{
"name": "4. Windows x64 Release",
Expand All @@ -46,7 +46,7 @@
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "--timeout 30"
"ctestCommandArgs": "--timeout 30 -j 4"
},
{
"name": "5. Linux x86 Debug",
Expand All @@ -56,7 +56,7 @@
"remoteCopySourcesExclusionList": [ ".vs", ".git", "out" ],
"cmakeCommandArgs": "-DLIBNETWRK_LINUX_ARCHITECTURE:STRING=x86",
"buildCommandArgs": "",
"ctestCommandArgs": "--timeout 30",
"ctestCommandArgs": "--timeout 30 -j 4",
"inheritEnvironments": [ "linux_x86" ],
"intelliSenseMode": "linux-gcc-x86",
"remoteMachineName": "${defaultRemoteMachineName}",
Expand All @@ -76,7 +76,7 @@
"remoteCopySourcesExclusionList": [ ".vs", ".git", "out" ],
"cmakeCommandArgs": "-DLIBNETWRK_LINUX_ARCHITECTURE:STRING=x86",
"buildCommandArgs": "",
"ctestCommandArgs": "--timeout 30",
"ctestCommandArgs": "--timeout 30 -j 4",
"inheritEnvironments": [ "linux_x86" ],
"intelliSenseMode": "linux-gcc-x86",
"remoteMachineName": "${defaultRemoteMachineName}",
Expand All @@ -96,7 +96,7 @@
"remoteCopySourcesExclusionList": [ ".vs", ".git", "out" ],
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "--timeout 30",
"ctestCommandArgs": "--timeout 30 -j 4",
"inheritEnvironments": [ "linux_x64" ],
"intelliSenseMode": "linux-gcc-x64",
"remoteMachineName": "${defaultRemoteMachineName}",
Expand All @@ -116,7 +116,7 @@
"remoteCopySourcesExclusionList": [ ".vs", ".git", "out" ],
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "--timeout 30",
"ctestCommandArgs": "--timeout 30 -j 4",
"inheritEnvironments": [ "linux_x64" ],
"intelliSenseMode": "linux-gcc-x64",
"remoteMachineName": "${defaultRemoteMachineName}",
Expand Down
18 changes: 11 additions & 7 deletions examples/tcp_echo/tcp_echo_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,26 @@ using namespace libnetwrk;

class tcp_echo_service : public tcp_service<service_desc> {
public:
tcp_echo_service() : tcp_service() {}
tcp_echo_service() : tcp_service() {
set_message_callback([this](auto command, auto message) {
ev_message(command, message);
});
}

void ev_message(owned_message_t& msg) override {
void ev_message(command_t command, owned_message_t* msg) {
message_t response;
switch (msg.msg.command()) {
switch (command) {
case commands::c2s_echo: {
std::string text;
msg.msg >> text;
msg->msg >> text;

LIBNETWRK_INFO(this->name, "{}:{}\t{}",
msg.sender->get_ip().c_str(), msg.sender->get_port(), text);
LIBNETWRK_INFO(get_name(), "{}:{}\t{}",
msg->sender->get_ip().c_str(), msg->sender->get_port(), text);

response.set_command(commands::s2c_echo);
response << text;

msg.sender->send(response);
msg->sender->send(response);
break;
}
default: break;
Expand Down
Loading
Loading