client_wrapper.hxx, socket_wrapper.hxx: reorder member initialization order
[libt2n] / src / socket_handler.hxx
CommitLineData
19facd85
TJ
1/*
2Copyright (C) 2006 by Intra2net AG - Gerd v. Egidy
3
4The software in this package is distributed under the GNU General
5Public License version 2 (with a special exception described below).
6
7A copy of GNU General Public License (GPL) is included in this distribution,
8in the file COPYING.GPL.
9
10As a special exception, if other files instantiate templates or use macros
11or inline functions from this file, or you compile this file and link it
12with other works to produce a work based on this file, this file
13does not by itself cause the resulting work to be covered
14by the GNU General Public License.
15
16However the source code for this file must still be made available
17in accordance with section (3) of the GNU General Public License.
18
19This exception does not invalidate any other reasons why a work based
20on this file might be covered by the GNU General Public License.
21*/
a11e19b7
GE
22#ifndef __LIBT2N_SOCKET_HANDLER
23#define __LIBT2N_SOCKET_HANDLER
24
a7170401
GE
25#include <iostream>
26
a11e19b7
GE
27#include "types.hxx"
28
29namespace libt2n
30{
31
94247295
GE
32/** @brief handles socket based communication.
33 Don't use directly, use socket_server or socket_client_connection instead.
34*/
a11e19b7
GE
35class socket_handler
36{
37 private:
517d1214
RP
38 static const unsigned int default_recv_buffer_size=2048;
39 static const unsigned int default_write_block_size=4096;
c7857475 40 static const long long default_write_timeout=30000000;
a11e19b7
GE
41
42 socket_type_value socket_type;
43
9a5d7790 44 bool data_waiting(long long usec_timeout,long long *usec_timeout_remaining=NULL);
c7857475 45 void wait_ready_to_write(int socket, long long write_block_timeout);
a11e19b7
GE
46
47 protected:
48 int sock;
517d1214
RP
49 unsigned int recv_buffer_size;
50 unsigned int write_block_size;
c7857475 51 long long write_timeout;
a11e19b7 52
517d1214 53 socket_handler(int _sock, socket_type_value _socket_type);
56f3994d 54 ~socket_handler();
a11e19b7
GE
55
56 void set_socket_options(int sock);
57
a7170401
GE
58 virtual std::ostream* get_logstream(log_level_values level)
59 { return NULL; }
a11e19b7 60
94247295
GE
61 void socket_write(const std::string& data);
62
63 virtual void close();
a11e19b7 64
9a5d7790 65 bool fill_buffer(std::string& buffer, long long usec_timeout, long long* usec_timeout_remaining=NULL);
a11e19b7
GE
66 bool fill_buffer(std::string& buffer);
67
94247295 68 public:
517d1214 69 /// is this a tcp or unix socket connection
94247295
GE
70 socket_type_value get_type()
71 { return socket_type; }
a11e19b7 72
1fdd03d2
CR
73 int get_socket()
74 { return sock; }
75
644c4d26 76 bool is_closed();
517d1214
RP
77
78 void set_recv_buffer_size(unsigned int new_recv_buffer_size);
79 void set_write_block_size(unsigned int new_write_block_size);
c7857475 80 void set_write_timeout(long long new_write_timeout);
517d1214
RP
81
82 unsigned int get_recv_buffer_size() const { return recv_buffer_size; }
83 unsigned int get_write_block_size() const { return write_block_size; }
c7857475 84 long long get_write_timeout() const { return write_timeout; }
a11e19b7
GE
85};
86
87}
88
89#endif