Skip to content

Commit 3729aee

Browse files
committed
Code cleanup
1 parent 5aaaf1b commit 3729aee

File tree

4 files changed

+32
-27
lines changed

4 files changed

+32
-27
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CC=g++
22
CFLAGS=-Wall -Wextra -c -Wfloat-equal -Wundef -Wcast-align -Wwrite-strings -Wlogical-op -Wmissing-declarations -Wredundant-decls -Wshadow -Woverloaded-virtual
3-
BOOSTFLAGS=-lboost_system -lboost_thread -lpthread -pthread -lboost_program_options -std=c++14
3+
BOOSTFLAGS=-lboost_system -lboost_thread -lpthread -std=c++14
44

55
EXECUTABLE_S=server
66
EXECUTABLE_C=client

main_client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int main(int argc, char* argv[])
2626
/*EXIT*/
2727
//return 0;
2828
}
29-
catch (std::exception& e)
29+
catch (const std::exception& e)
3030
{
3131
std::cerr << "CLIENT> Exception: " << e.what() << "\n";
3232
}

main_server.cpp

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ using namespace cli;
77

88
int main(void)
99
{
10-
try
11-
{
12-
boost::asio::io_context io_context;
10+
boost::asio::io_service io_service;
1311
unsigned int port;
1412
bool set_port = false;
1513

@@ -20,14 +18,21 @@ int main(void)
2018
{
2119
if (set_port)
2220
{
23-
server s(io_context, port);
24-
std::cout << "\tSERVER STARTED ON " << port << std::endl;
25-
if(io_context.stopped())
26-
io_context.restart();
27-
io_context.run();
21+
try
22+
{
23+
server s(io_service, port);
24+
std::cout << "\tSERVER STARTED ON " << port << std::endl;
25+
if(io_service.stopped())
26+
io_service.restart();
27+
io_service.run();
28+
}
29+
catch (const std::exception& e)
30+
{
31+
std::cerr << "SERVER> Exception: " << e.what() << "\n";
32+
}
2833
}
2934
else {
30-
out << "You must set port for server. Use: \"setPort <value>\"" << "\n";
35+
out << "You must set port for server. Use: \"setPort <int>\"" << "\n";
3136
}
3237
},
3338
"Start server");
@@ -54,9 +59,16 @@ int main(void)
5459
[&](std::ostream& out)
5560
{
5661
if (set_port){
57-
if (!io_context.stopped())
58-
io_context.stop();
59-
out << "\tSTOPED ON PORT " << port << std::endl;
62+
try
63+
{
64+
if (!io_service.stopped())
65+
io_service.stop();
66+
out << "\tSTOPED ON PORT " << port << std::endl;
67+
}
68+
catch (const std::exception& e)
69+
{
70+
std::cerr << "SERVER> Exception: " << e.what() << "\n";
71+
}
6072
}
6173
else {
6274
out << "You don't specify the port or don't start the server." << "\n";
@@ -65,21 +77,16 @@ int main(void)
6577
"Stop server");
6678

6779
Cli cli(std::move(rootMenu));
68-
cli.ExitAction([&io_context](auto& out)
80+
cli.ExitAction([&io_service](auto& out)
6981
{
70-
if (!io_context.stopped())
71-
io_context.stop();
82+
if (!io_service.stopped())
83+
io_service.stop();
7284

7385
out << "\tEXIT. Goodbye!\n";
7486
});
7587

7688
CliFileSession input(cli);
7789
input.Start();
78-
}
79-
catch (std::exception& e)
80-
{
81-
std::cerr << "SERVER> Exception: " << e.what() << "\n";
82-
}
8390

8491
return 0;
8592
}

server.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#pragma once
2-
#include <cstdlib>
2+
33
#include <iostream>
4-
#include <memory>
5-
#include <utility>
64
#include <boost/asio.hpp>
75

86
using boost::asio::ip::tcp;
@@ -48,9 +46,9 @@ class session : public std::enable_shared_from_this<session>
4846
class server
4947
{
5048
public:
51-
server(boost::asio::io_context& io_context, const unsigned int port) :
49+
server(boost::asio::io_service& io_service, const unsigned int port) :
5250
ep(tcp::v4(), port),
53-
acceptor_(io_context, ep),
51+
acceptor_(io_service, ep),
5452
session_id(0)
5553
{
5654
do_accept();

0 commit comments

Comments
 (0)