Skip to content

Commit

Permalink
Merge pull request #63 from robotology/fix/namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicogene authored Jun 19, 2023
2 parents 566ce54 + 6d8b613 commit 0cc3e53
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
9 changes: 5 additions & 4 deletions src/blocktestcore/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <chrono>

using namespace std::literals::chrono_literals;
using namespace boost::asio::ip;

Connection::Connection(boost::asio::io_service& io_service): socket_(io_service)
{
Expand All @@ -24,13 +25,13 @@ void Connection::handleRead(const boost::system::error_code& err,size_t bytes_tr
if(bytes_transferred==0)
{
std::cout<<"Transferred 0"<<std::endl;
}
}
else
{
std::cout<<readBuffer_<<std::endl;;
}
}
start();
}
}
}

tcp::socket& Connection::socket()
Expand All @@ -45,5 +46,5 @@ void Connection::start()
boost::bind(&Connection::handleRead,
shared_from_this(),
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
boost::asio::placeholders::bytes_transferred));
}
12 changes: 5 additions & 7 deletions src/blocktestcore/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#include <boost/asio.hpp>
#include <boost/enable_shared_from_this.hpp>

using boost::asio::ip::tcp;

class Connection : public boost::enable_shared_from_this<Connection>
{
public:
Expand All @@ -25,18 +23,18 @@ class Connection : public boost::enable_shared_from_this<Connection>
return pointer(new Connection(io_service));
}

tcp::socket& socket();
boost::asio::ip::tcp::socket& socket();

void start();

private:
Connection(boost::asio::io_service& io_service);

void handleWrite(const boost::system::error_code& err,size_t bytes_transferred);
void handleRead(const boost::system::error_code& err,size_t bytes_transferred);
void handleWrite(const boost::system::error_code& err,size_t bytes_transferred);
void handleRead(const boost::system::error_code& err,size_t bytes_transferred);

static const int size_{1024};
char readBuffer_[size_];
boost::asio::streambuf response_;
tcp::socket socket_;
boost::asio::ip::tcp::socket socket_;
};
5 changes: 3 additions & 2 deletions src/blocktestcore/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
#include <chrono>

using namespace std::literals::chrono_literals;
using namespace boost::asio::ip;

Server::Server(boost::asio::io_service& io):io_(io),acceptor_(io, tcp::endpoint(tcp::v4(), 9876))
{
{
}

void Server::init()
{
{
startAccept();
}

Expand Down
7 changes: 2 additions & 5 deletions src/blocktestcore/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
#pragma once
#include <boost/asio.hpp>
#include "connection.h"

using boost::asio::ip::tcp;

class Server
{
public:
Expand All @@ -24,9 +21,9 @@ class Server
private:
const unsigned int port_{9876};
boost::asio::io_service& io_;
tcp::acceptor acceptor_;
boost::asio::ip::tcp::acceptor acceptor_;
Connection::pointer newConnection_;

void startAccept();
void handleAccept(Connection::pointer newConnection,const boost::system::error_code& error);
};

0 comments on commit 0cc3e53

Please sign in to comment.