Debian Codegraph @

src/SocketArray.hpp

raw
1 // SocketArray - wrapper for clean handling of an array of Sockets
2
3 // For all support, instructions and copyright go to:
4 // http://e2guardian.org/
5 // Released under the GPL v2, with the OpenSSL exception described in the README file.
6
7 #ifndef __HPP_SOCKETARRAY
8 #define __HPP_SOCKETARRAY
9
10 // INCLUDES
11 #include "Socket.hpp"
12 #include "String.hpp"
13
14 #include <deque>
15 #include<thread>
16 #include <vector>
17
18 // DECLARATIONS
19
20 class SocketArray
21 {
22 public:
23 // set sensible defaults
24 SocketArray()
25 : drawer(NULL), socknum(0){};
26 // delete all sockets
27 ~SocketArray();
28
29 // close all old socks & create specified amount of new ones
30 void reset(int sockcount);
31
32 // just delete the lot of 'em
33 void deleteAll();
34
35 // bind our sockets to the given IPs
36 int bindAll(std::deque<String> &ips, std::deque<String> &ports, int &index, int ct_type);
37 // bind just the one, to all available IPs
38 int bindSingle(int port);
39 int bindSingle(unsigned int index, int port, unsigned int CT_type);
40 int bindSingleM(std::deque<String> &port, int &index, int ct_type);
41 // set all sockets listening with given kernel queue length
42 int listenAll(int queue);
43
44 // shove all socket FDs into the given array (pass in unallocated)
45 int *getFDAll();
46
47 unsigned int getType(unsigned int ind);
48
49 // try connecting to all our sockets which are still open to allow tidy close
50 void self_connect();
51
52 // array dereference operator
53 Socket *operator[](int i)
54 {
55 return &(drawer[i]);
56 };
57
58 private:
59 // our sock collection container
60 Socket *drawer;
61 std::vector<unsigned int> lc_types; // holds listening connection type i.e. LC_PROXY, LC_THTTPS, LC_ICAP
62 // how many sockets we have
63 unsigned int socknum;
64 };
65
66 #endif