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_HANDLER 00020 #define __LIBT2N_SOCKET_HANDLER 00021 00022 #include <iostream> 00023 00024 #include "types.hxx" 00025 00026 namespace libt2n 00027 { 00028 00032 class socket_handler 00033 { 00034 private: 00035 static const unsigned int default_recv_buffer_size=2048; 00036 static const unsigned int default_write_block_size=4096; 00037 static const long long default_write_timeout=30000000; 00038 00039 socket_type_value socket_type; 00040 00041 bool data_waiting(long long usec_timeout,long long *usec_timeout_remaining=NULL); 00042 void wait_ready_to_write(int socket, long long write_block_timeout); 00043 00044 protected: 00045 int sock; 00046 unsigned int recv_buffer_size; 00047 unsigned int write_block_size; 00048 long long write_timeout; 00049 00050 socket_handler(int _sock, socket_type_value _socket_type); 00051 00052 void set_socket_options(int sock); 00053 00054 virtual std::ostream* get_logstream(log_level_values level) 00055 { return NULL; } 00056 00057 void socket_write(const std::string& data); 00058 00059 virtual void close(); 00060 00061 bool fill_buffer(std::string& buffer, long long usec_timeout, long long* usec_timeout_remaining=NULL); 00062 bool fill_buffer(std::string& buffer); 00063 00064 public: 00066 socket_type_value get_type() 00067 { return socket_type; } 00068 00069 bool is_closed(); 00070 00071 void set_recv_buffer_size(unsigned int new_recv_buffer_size); 00072 void set_write_block_size(unsigned int new_write_block_size); 00073 void set_write_timeout(long long new_write_timeout); 00074 00075 unsigned int get_recv_buffer_size() const { return recv_buffer_size; } 00076 unsigned int get_write_block_size() const { return write_block_size; } 00077 long long get_write_timeout() const { return write_timeout; } 00078 }; 00079 00080 } 00081 00082 #endif
1.5.6