Intra2net AG

socket_server.hxx

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2006 by Intra2net AG - Gerd v. Egidy
00003 
00004 The software in this package is distributed under the GNU General
00005 Public License version 2 (with a special exception described below).
00006 
00007 A copy of GNU General Public License (GPL) is included in this distribution,
00008 in the file COPYING.GPL.
00009 
00010 As a special exception, if other files instantiate templates or use macros
00011 or inline functions from this file, or you compile this file and link it
00012 with other works to produce a work based on this file, this file
00013 does not by itself cause the resulting work to be covered
00014 by the GNU General Public License.
00015 
00016 However the source code for this file must still be made available
00017 in accordance with section (3) of the GNU General Public License.
00018 
00019 This exception does not invalidate any other reasons why a work based
00020 on this file might be covered by the GNU General Public License.
00021 */
00022 #ifndef __LIBT2N_SOCKET_SERVER
00023 #define __LIBT2N_SOCKET_SERVER
00024 
00025 #include <sys/types.h>
00026 #include <string>
00027 #include <set>
00028 
00029 #include "server.hxx"
00030 #include "socket_handler.hxx"
00031 #include "types.hxx"
00032 
00033 namespace libt2n
00034 {
00035 
00036 class socket_server_connection;
00037 
00045 class socket_server : public socket_handler, public server
00046 {
00047     friend class socket_server_connection;
00048 
00049     private:
00050         fd_set connection_set;
00051         std::string unix_path;
00052         std::set<int> sockets_set;
00053 
00054         void start_listening();
00055 
00056         void new_connection();
00057 
00058         bool fill_connection_buffers();
00059         void remove_connection_socket(int sock);
00060 
00061     protected:
00062         std::ostream* get_logstream(log_level_values level)
00063             { return server::get_logstream(level); }
00064 
00065     public:
00066         socket_server(int port, const std::string& ip="0.0.0.0");
00067         socket_server(const std::string& path, mode_t filemode=00770, const std::string& user="", const std::string& group="");
00068 
00069         ~socket_server();
00070 
00071         bool fill_buffer(long long usec_timeout=-1,long long* usec_timeout_remaining=NULL);
00072         std::set<int> get_sockets_set()
00073             { return sockets_set; };
00074 };
00075 
00080 class socket_server_connection : public socket_handler, public server_connection
00081 {
00082     friend class socket_server;
00083 
00084     private:
00085         socket_server_connection(int _sock, socket_type_value _stype, int _timeout)
00086            : socket_handler(_sock,_stype), server_connection(_timeout)
00087            { }
00088 
00089         ~socket_server_connection();
00090 
00091         std::ostream* get_logstream(log_level_values level)
00092             { return server_connection::get_logstream(level); }
00093 
00094         void real_write(const std::string& data)
00095             { socket_write(data); }
00096 
00097     public:
00098         bool fill_buffer(long long usec_timeout=-1,long long* usec_timeout_remaining=NULL);
00099 
00100         virtual void close();
00101 };
00102 
00103 }
00104 
00105 #endif

Generated on 13 May 2015 by  doxygen 1.6.1
© Intra2net AG 2024 | Legal | Contact