/*************************************************************************** * Copyright (C) 2006 by Gerd v. Egidy * * gve@intra2net.com * * * * This library is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License version * * 2.1 as published by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef __LIBT2N_SOCKET_SERVER #define __LIBT2N_SOCKET_SERVER #include #include #include "server.hxx" #include "socket_handler.hxx" #include "types.hxx" namespace libt2n { /** Socket based server class */ class socket_server : public socket_handler, public server { private: fd_set connection_set; std::string unix_path; void new_connection(); protected: void log(log_level_values level, const std::string& message) { log(level,message.c_str()); } void log(log_level_values level, const char* message) { server::log(level,message); } public: socket_server(int port, const std::string& ip="0.0.0.0"); socket_server(const std::string& path, mode_t filemode=00770, const std::string& user="", const std::string& group=""); ~socket_server(); void fill_buffer(long long usec_timeout=-1); void fill_connection_buffers(); void remove_connection_socket(int sock); }; /** Socket based connection class */ class socket_server_connection : public socket_handler, public server_connection { friend class socket_server; private: socket_server_connection(int _sock, socket_type_value _stype, int _timeout) : server_connection(_timeout), socket_handler(_sock,_stype) { } void log(log_level_values level, const char* message); void real_write(const std::string& data) { socket_write(data); } public: void fill_buffer(long long usec_timeout=-1) { socket_handler::fill_buffer(buffer,usec_timeout); } void close(); }; } #endif