socket_server.hxx

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2006 by Gerd v. Egidy                                   *
00003  *   gve@intra2net.com                                                     *
00004  *                                                                         *
00005  *   This library is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License version   *
00007  *   2.1 as published by the Free Software Foundation.                     *
00008  *                                                                         *
00009  *   This library is distributed in the hope that it will be useful,       *
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012  *   GNU Lesser General Public License for more details.                   *
00013  *                                                                         *
00014  *   You should have received a copy of the GNU Lesser General Public      *
00015  *   License along with this program; if not, write to the                 *
00016  *   Free Software Foundation, Inc.,                                       *
00017  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
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

Generated on Fri Sep 26 15:36:59 2008 for libt2n by  doxygen 1.5.6