Intra2net AG

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

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