… | |
… | |
2 | * Copyright © 2005 Atheme Development Group |
2 | * Copyright © 2005 Atheme Development Group |
3 | * Rights to this code are as documented in doc/pod/license.pod. |
3 | * Rights to this code are as documented in doc/pod/license.pod. |
4 | * |
4 | * |
5 | * This contains the connection_t structure. |
5 | * This contains the connection_t structure. |
6 | * |
6 | * |
7 | * $Id: connection.h,v 1.4 2007/08/30 19:56:19 pippijn Exp $ |
7 | * $Id: connection.h,v 1.5 2007/09/05 11:23:13 pippijn Exp $ |
8 | */ |
8 | */ |
9 | |
9 | |
10 | #ifndef CONNECTION_H |
10 | #ifndef CONNECTION_H |
11 | #define CONNECTION_H |
11 | #define CONNECTION_H |
12 | |
12 | |
… | |
… | |
29 | : firstused (0), firstfree (0) |
29 | : firstused (0), firstfree (0) |
30 | { |
30 | { |
31 | } |
31 | } |
32 | }; |
32 | }; |
33 | |
33 | |
|
|
34 | enum connection_flag |
|
|
35 | { |
|
|
36 | CF_UPLINK = 1 << 0, |
|
|
37 | CF_DCCOUT = 1 << 1, |
|
|
38 | CF_DCCIN = 1 << 2, |
|
|
39 | |
|
|
40 | CF_CONNECTING = 1 << 3, |
|
|
41 | CF_LISTENING = 1 << 4, |
|
|
42 | CF_CONNECTED = 1 << 5, |
|
|
43 | CF_DEAD = 1 << 6, |
|
|
44 | |
|
|
45 | CF_NONEWLINE = 1 << 7, |
|
|
46 | CF_SEND_EOF = 1 << 8, /* shutdown(2) write end if sendque empty */ |
|
|
47 | CF_SEND_DEAD = 1 << 9 /* write end shut down */ |
|
|
48 | }; |
|
|
49 | |
34 | class connection_t : public zero_initialised |
50 | class connection_t : public object, public zero_initialised |
35 | { |
51 | { |
36 | void _destroy () |
52 | void _destroy () |
37 | { |
53 | { |
38 | delete this; |
54 | delete this; |
39 | } |
55 | } |
… | |
… | |
42 | { |
58 | { |
43 | functor::callback1<connection_t *> connected; |
59 | functor::callback1<connection_t *> connected; |
44 | }; |
60 | }; |
45 | |
61 | |
46 | public: |
62 | public: |
47 | enum flag |
63 | unsigned flags; |
48 | { |
|
|
49 | CF_UPLINK = 1 << 0, |
|
|
50 | CF_DCCOUT = 1 << 1, |
|
|
51 | CF_DCCIN = 1 << 2, |
|
|
52 | |
|
|
53 | CF_CONNECTING = 1 << 3, |
|
|
54 | CF_LISTENING = 1 << 4, |
|
|
55 | CF_CONNECTED = 1 << 5, |
|
|
56 | CF_DEAD = 1 << 6, |
|
|
57 | |
|
|
58 | CF_NONEWLINE = 1 << 7, |
|
|
59 | CF_SEND_EOF = 1 << 8, /* shutdown(2) write end if sendque empty */ |
|
|
60 | CF_SEND_DEAD = 1 << 9 /* write end shut down */ |
|
|
61 | }; |
|
|
62 | |
64 | |
63 | bool is_uplink () { return flags & CF_UPLINK; } |
65 | bool is_uplink () { return flags & CF_UPLINK; } |
64 | bool is_dcc () { return flags & (CF_DCCOUT | CF_DCCIN); } |
66 | bool is_dcc () { return flags & (CF_DCCOUT | CF_DCCIN); } |
65 | bool is_dccout () { return flags & CF_DCCOUT; } |
67 | bool is_dccout () { return flags & CF_DCCOUT; } |
66 | bool is_dccin () { return flags & CF_DCCIN; } |
68 | bool is_dccin () { return flags & CF_DCCIN; } |
67 | bool is_dead () { return flags & CF_DEAD; } |
69 | bool is_dead () { return flags & CF_DEAD; } |
68 | bool is_connecting () { return flags & CF_CONNECTING; } |
70 | bool is_connecting () { return flags & CF_CONNECTING; } |
69 | bool is_listening () { return flags & CF_LISTENING; } |
71 | bool is_listening () { return flags & CF_LISTENING; } |
70 | |
72 | |
71 | public: |
73 | public: |
72 | int index; |
74 | int index; // for list_type |
|
|
75 | typedef indexing_vector<connection_t> list_type; |
|
|
76 | static list_type list; |
|
|
77 | |
|
|
78 | public: |
73 | |
79 | |
74 | typedef std::deque<packetqueue *> queue; |
80 | typedef std::deque<packetqueue *> queue; |
75 | |
81 | |
76 | char name[HOSTLEN]; |
82 | char name[HOSTLEN]; |
77 | char hbuf[BUFSIZE + 1]; |
83 | char hbuf[BUFSIZE + 1]; |
… | |
… | |
89 | struct sockaddr saddr; |
95 | struct sockaddr saddr; |
90 | unsigned int saddr_size; |
96 | unsigned int saddr_size; |
91 | |
97 | |
92 | void (*read_handler) (connection_t *); |
98 | void (*read_handler) (connection_t *); |
93 | void (*write_handler) (connection_t *); |
99 | void (*write_handler) (connection_t *); |
94 | |
|
|
95 | unsigned flags; |
|
|
96 | |
100 | |
97 | void (*recvq_handler) (connection_t *); |
101 | void (*recvq_handler) (connection_t *); |
98 | void (*close_handler) (connection_t *); |
102 | void (*close_handler) (connection_t *); |
99 | connection_t *listener; |
103 | connection_t *listener; |
100 | void *userdata; |
104 | void *userdata; |
… | |
… | |
120 | static connection_t *find (int); |
124 | static connection_t *find (int); |
121 | static void select (time_t delay); |
125 | static void select (time_t delay); |
122 | static int count (void); |
126 | static int count (void); |
123 | }; |
127 | }; |
124 | |
128 | |
125 | typedef indexing_vector<connection_t> connection_vector; |
|
|
126 | E connection_vector connlist; |
|
|
127 | |
|
|
128 | #endif |
129 | #endif |