… | |
… | |
3 | * Rights to this code are documented in doc/pod/license.pod. |
3 | * Rights to this code are documented in doc/pod/license.pod. |
4 | * |
4 | * |
5 | * Copyright © 2005-2007 Atheme Project (http://www.atheme.org) |
5 | * Copyright © 2005-2007 Atheme Project (http://www.atheme.org) |
6 | */ |
6 | */ |
7 | |
7 | |
8 | static char const rcsid[] = "$Id: connection.C,v 1.5 2007/08/30 19:56:24 pippijn Exp $"; |
8 | static char const rcsid[] = "$Id: connection.C,v 1.6 2007/09/05 11:23:15 pippijn Exp $"; |
9 | |
9 | |
10 | #include "atheme.h" |
10 | #include "atheme.h" |
11 | #include "internal.h" |
11 | #include "internal.h" |
12 | #include "datastream.h" |
12 | #include "datastream.h" |
13 | #include "connection.h" |
13 | #include "connection.h" |
14 | |
14 | |
15 | connection_vector connlist; |
15 | connection_t::list_type connection_t::list; |
16 | connection_t::callbacks connection_t::callback; |
16 | connection_t::callbacks connection_t::callback; |
17 | |
17 | |
18 | void |
18 | void |
19 | init_netio (void) |
19 | init_netio (void) |
20 | { |
20 | { |
… | |
… | |
83 | getpeername (cptr->fd, &cptr->saddr, &cptr->saddr_size); |
83 | getpeername (cptr->fd, &cptr->saddr, &cptr->saddr_size); |
84 | cptr->sa = (struct sockaddr_in *) &cptr->saddr; |
84 | cptr->sa = (struct sockaddr_in *) &cptr->saddr; |
85 | |
85 | |
86 | inet_ntop (AF_INET, &cptr->sa->sin_addr, cptr->hbuf, BUFSIZE); |
86 | inet_ntop (AF_INET, &cptr->sa->sin_addr, cptr->hbuf, BUFSIZE); |
87 | |
87 | |
88 | connlist.insert (cptr); |
88 | connection_t::list.insert (cptr); |
89 | |
89 | |
90 | return cptr; |
90 | return cptr; |
91 | } |
91 | } |
92 | |
92 | |
93 | /* |
93 | /* |
… | |
… | |
104 | */ |
104 | */ |
105 | connection_t * |
105 | connection_t * |
106 | connection_t::find (int fd) |
106 | connection_t::find (int fd) |
107 | { |
107 | { |
108 | connection_t *cptr; |
108 | connection_t *cptr; |
109 | connection_vector::iterator it = connlist.begin (); |
109 | connection_t::list_type::iterator it = connection_t::list.begin (); |
110 | connection_vector::iterator et = connlist.end (); |
110 | connection_t::list_type::iterator et = connection_t::list.end (); |
111 | |
111 | |
112 | while (it != et) |
112 | while (it != et) |
113 | { |
113 | { |
114 | cptr = *it; |
114 | cptr = *it; |
115 | |
115 | |
… | |
… | |
135 | * none |
135 | * none |
136 | */ |
136 | */ |
137 | int |
137 | int |
138 | connection_t::count (void) |
138 | connection_t::count (void) |
139 | { |
139 | { |
140 | return connlist.size (); |
140 | return connection_t::list.size (); |
141 | } |
141 | } |
142 | |
142 | |
143 | /* |
143 | /* |
144 | * connection_close() |
144 | * connection_close() |
145 | * |
145 | * |
… | |
… | |
153 | * the connection is closed. |
153 | * the connection is closed. |
154 | */ |
154 | */ |
155 | void |
155 | void |
156 | connection_t::close () |
156 | connection_t::close () |
157 | { |
157 | { |
158 | connection_vector::iterator it; |
158 | connection_t::list_type::iterator it; |
159 | int errno1, errno2; |
159 | int errno1, errno2; |
160 | #ifdef SO_ERROR |
160 | #ifdef SO_ERROR |
161 | socklen_t len = sizeof (errno2); |
161 | socklen_t len = sizeof (errno2); |
162 | #endif |
162 | #endif |
163 | |
163 | |
164 | it = connlist.find (this); |
164 | it = connection_t::list.find (this); |
165 | if (it == connlist.end ()) |
165 | if (it == connection_t::list.end ()) |
166 | { |
166 | { |
167 | slog (LG_DEBUG, "connection_close(): connection %p is not registered!", this); |
167 | slog (LG_DEBUG, "connection_close(): connection %p is not registered!", this); |
168 | return; |
168 | return; |
169 | } |
169 | } |
170 | |
170 | |
… | |
… | |
184 | close_handler (this); |
184 | close_handler (this); |
185 | |
185 | |
186 | /* close the fd */ |
186 | /* close the fd */ |
187 | ::close (fd); |
187 | ::close (fd); |
188 | |
188 | |
189 | connlist.erase (this); |
189 | connection_t::list.erase (this); |
190 | |
190 | |
191 | sendqrecvq_free (this); |
191 | sendqrecvq_free (this); |
192 | |
192 | |
193 | delete this; |
193 | delete this; |
194 | } |
194 | } |
… | |
… | |
243 | * for all connections accepted on this listener |
243 | * for all connections accepted on this listener |
244 | */ |
244 | */ |
245 | void |
245 | void |
246 | connection_t::close_soon_children () |
246 | connection_t::close_soon_children () |
247 | { |
247 | { |
248 | connection_vector::iterator it = connlist.begin (); |
248 | connection_t::list_type::iterator it = connection_t::list.begin (); |
249 | connection_vector::iterator et = connlist.end (); |
249 | connection_t::list_type::iterator et = connection_t::list.end (); |
250 | connection_t *cptr2; |
250 | connection_t *cptr2; |
251 | |
251 | |
252 | if (is_listening ()) |
252 | if (is_listening ()) |
253 | { |
253 | { |
254 | while (it != et) |
254 | while (it != et) |
… | |
… | |
276 | * connection_close() called on all registered connections |
276 | * connection_close() called on all registered connections |
277 | */ |
277 | */ |
278 | void |
278 | void |
279 | connection_t::close_all (void) |
279 | connection_t::close_all (void) |
280 | { |
280 | { |
281 | while (!connlist.empty ()) |
281 | while (!connection_t::list.empty ()) |
282 | connlist.back ()->close (); |
282 | connection_t::list.back ()->close (); |
283 | } |
283 | } |
284 | |
284 | |
285 | /* |
285 | /* |
286 | * connection_t::open_tcp() |
286 | * connection_t::open_tcp() |
287 | * |
287 | * |
… | |
… | |
523 | void |
523 | void |
524 | connection_t::stats (void (*stats_cb) (char const * const , void *), void *privdata) |
524 | connection_t::stats (void (*stats_cb) (char const * const , void *), void *privdata) |
525 | { |
525 | { |
526 | char buf[160]; |
526 | char buf[160]; |
527 | char buf2[20]; |
527 | char buf2[20]; |
528 | connection_vector::iterator it = connlist.begin (); |
528 | connection_t::list_type::iterator it = connection_t::list.begin (); |
529 | connection_vector::iterator et = connlist.end (); |
529 | connection_t::list_type::iterator et = connection_t::list.end (); |
530 | |
530 | |
531 | while (it != et) |
531 | while (it != et) |
532 | { |
532 | { |
533 | connection_t *c = *it; |
533 | connection_t *c = *it; |
534 | |
534 | |