socket_server.hxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __LIBT2N_SOCKET_SERVER
00020 #define __LIBT2N_SOCKET_SERVER
00021
00022 #include <sys/types.h>
00023 #include <string>
00024
00025 #include "server.hxx"
00026 #include "socket_handler.hxx"
00027 #include "types.hxx"
00028
00029 namespace libt2n
00030 {
00031
00032 class socket_server_connection;
00033
00041 class socket_server : public socket_handler, public server
00042 {
00043 friend class socket_server_connection;
00044
00045 private:
00046 fd_set connection_set;
00047 std::string unix_path;
00048
00049 void start_listening();
00050
00051 void new_connection();
00052
00053 bool fill_connection_buffers();
00054 void remove_connection_socket(int sock);
00055
00056 protected:
00057 std::ostream* get_logstream(log_level_values level)
00058 { return server::get_logstream(level); }
00059
00060 public:
00061 socket_server(int port, const std::string& ip="0.0.0.0");
00062 socket_server(const std::string& path, mode_t filemode=00770, const std::string& user="", const std::string& group="");
00063
00064 ~socket_server();
00065
00066 bool fill_buffer(long long usec_timeout=-1,long long* usec_timeout_remaining=NULL);
00067 };
00068
00073 class socket_server_connection : public socket_handler, public server_connection
00074 {
00075 friend class socket_server;
00076
00077 private:
00078 socket_server_connection(int _sock, socket_type_value _stype, int _timeout)
00079 : server_connection(_timeout), socket_handler(_sock,_stype)
00080 { }
00081
00082 std::ostream* get_logstream(log_level_values level)
00083 { return server_connection::get_logstream(level); }
00084
00085 void real_write(const std::string& data)
00086 { socket_write(data); }
00087
00088 public:
00089 bool fill_buffer(long long usec_timeout=-1,long long* usec_timeout_remaining=NULL)
00090 { return socket_handler::fill_buffer(buffer,usec_timeout,usec_timeout_remaining); }
00091
00092 void close();
00093 };
00094
00095 }
00096
00097 #endif