SockIt

TcpServer.h

Go to the documentation of this file.
00001 /*
00002  * File:   TcpServer.h
00003  * Author: jtedesco
00004  *
00005  * Created on May 26, 2011, 12:33 PM
00006  */
00007 
00008 #ifndef TCPSERVER_H
00009 #define TCPSERVER_H
00010 
00011 #include<set>
00012 
00013 #include "Tcp.h"
00014 #include "Server.h"
00015 #include "Logger.h"
00016 
00017 using boost::asio::ip::tcp;
00018 using std::set;
00019 
00024 class TcpServer: public Tcp, public Server
00025 {
00026 
00027     public:
00028 
00036         TcpServer(int port, boost::asio::io_service & io_service);
00037 
00046         TcpServer(int port, boost::asio::io_service & io_service, map<string, string> options);
00047 
00052         virtual ~TcpServer();
00053 
00059         virtual void start_listening();
00060 
00065         virtual void shutdown();
00066 
00070         virtual int get_port();
00071 
00081         FB_JSAPI_EVENT(disconnect, 1, (const string &));
00082 
00086         FB_JSAPI_EVENT(connect, 0, ());
00087 
00088     protected:
00089 
00090 
00095         void receive_handler(const boost::system::error_code & error_code, std::size_t bytesTransferred,
00096                 boost::shared_ptr<tcp::socket> connection, string host, int port);
00097 
00103         virtual void fire_error_event(const string & message);
00104 
00110         virtual void fire_disconnect_event(const string & message);
00111 
00118         virtual void fire_data_event(const string data, boost::shared_ptr<tcp::socket> connection);
00119 
00124         virtual void close();
00125 
00126     private:
00127 
00131         void init();
00132 
00136         void init_socket(boost::shared_ptr<tcp::socket> connection);
00137 
00141         TcpServer(const TcpServer &other);
00142 
00154         void accept_handler(const boost::system::error_code & error_code, boost::shared_ptr<tcp::socket> connection, string host, int port);
00155 
00159         boost::shared_ptr<tcp::acceptor> acceptor;
00160         
00162         set<boost::shared_ptr<tcp::socket> > connections;
00163 };
00164 
00165 #endif  /* TCPSERVER_H */
00166 
 All Classes Files Functions Variables Typedefs Friends Defines