30 #include <boost/shared_ptr.hpp>
31 #include <boost/enable_shared_from_this.hpp>
32 #include <boost/asio.hpp>
33 #include <boost/thread/thread.hpp>
38 #include <condition_variable>
40 using boost::asio::ip::tcp;
59 :
public boost::enable_shared_from_this<tcp_connection>
62 typedef boost::shared_ptr<tcp_connection>
pointer;
67 std::cout <<
"Call public destructor tcp_connection " << std::endl;
91 std::cout <<
"Call private constructor tcp_connection " << std::endl;
95 void handle_write(
const boost::system::error_code& error,
96 size_t bytes_transferred);
188 const boost::system::error_code& error);
Singleton class, stores all loaded stocks.
std::condition_variable loop_cv
tcp::acceptor acceptor_
...
void start_accept()
create a new tcp_connection to receive message
tcp_connection(boost::asio::io_service &io_service)
Private constructor.
void StopServer()
Stop the server.
std::string message_
Message received by the socket.
void StartServer()
Start the server.
TCPServer(StockManager *sm, unsigned int iport)
Constructor, io_service is a private data member (my_io_service).
boost::asio::io_service my_io_service
io_service needed for asimc.
bool is_running
Indicate if the server is running.
static pointer create(boost::asio::io_service &io_service)
Static function to create a new socket.
bool IsRunning()
Return the status of the server.
void LoopThread()
Function run by the internal thread.
void handle_accept(tcp_connection::pointer new_connection, const boost::system::error_code &error)
handle the received message: parse and send string data to StockManager.
virtual ~TCPServer()
Destructor.
Use with RealTime to receive messages from python ServerPortfolio.
tcp::socket & GetSocket()
unsigned int port
Port where the server listens.
std::thread t_
Internal thread.
void handle_write(const boost::system::error_code &error, size_t bytes_transferred)
Function called async.
StockManager * f_sm
Pointer to the StockManager singleton, will receive and treat the messages.
tcp::socket & socket()
Return the socket.
boost::shared_ptr< tcp_connection > pointer
void start()
Function to be executed when a message must be send back.
bool want_exit
Indicate the thread must exit, set in destructor only.
Define one connection of the server.
tcp::socket socket_
Store an io_service.
virtual ~tcp_connection()
Destructor.