… | |
… | |
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: poll.C,v 1.4 2007/08/28 17:08:12 pippijn Exp $"; |
8 | static char const rcsid[] = "$Id: poll.C,v 1.5 2007/08/30 19:56:26 pippijn Exp $"; |
9 | |
9 | |
10 | #include <sys/poll.h> |
10 | #include <sys/poll.h> |
11 | |
11 | |
12 | #include "atheme.h" |
12 | #include "atheme.h" |
13 | #include "internal.h" |
13 | #include "internal.h" |
14 | #include "datastream.h" |
14 | #include "datastream.h" |
|
|
15 | #include "connection.h" |
15 | |
16 | |
16 | /* |
17 | /* |
17 | * linux does not provide POLLWRNORM by default, and we're not _XOPEN_SOURCE. |
18 | * linux does not provide POLLWRNORM by default, and we're not _XOPEN_SOURCE. |
18 | * so.... we have to do this crap below. |
19 | * so.... we have to do this crap below. |
19 | */ |
20 | */ |
… | |
… | |
67 | { |
68 | { |
68 | connection_t *cptr = *it; |
69 | connection_t *cptr = *it; |
69 | |
70 | |
70 | cptr->pollslot = slot; |
71 | cptr->pollslot = slot; |
71 | |
72 | |
72 | if (CF_IS_CONNECTING (cptr) || sendq_nonempty (cptr)) |
73 | if (cptr->is_connecting () || sendq_nonempty (cptr)) |
73 | { |
74 | { |
74 | pollfds[slot].fd = cptr->fd; |
75 | pollfds[slot].fd = cptr->fd; |
75 | pollfds[slot].events |= POLLWRNORM; |
76 | pollfds[slot].events |= POLLWRNORM; |
76 | pollfds[slot].revents = 0; |
77 | pollfds[slot].revents = 0; |
77 | } |
78 | } |
… | |
… | |
85 | ++it; |
86 | ++it; |
86 | } |
87 | } |
87 | } |
88 | } |
88 | |
89 | |
89 | /* |
90 | /* |
90 | * connection_select() |
91 | * connection_t::select() |
91 | * |
92 | * |
92 | * inputs: |
93 | * inputs: |
93 | * delay in microseconds |
94 | * delay in microseconds |
94 | * |
95 | * |
95 | * outputs: |
96 | * outputs: |
… | |
… | |
97 | * |
98 | * |
98 | * side effects: |
99 | * side effects: |
99 | * registered sockets and their associated handlers are acted on. |
100 | * registered sockets and their associated handlers are acted on. |
100 | */ |
101 | */ |
101 | void |
102 | void |
102 | connection_select (time_t delay) |
103 | connection_t::select (time_t delay) |
103 | { |
104 | { |
104 | int sr; |
105 | int sr; |
105 | connection_vector::iterator it = connlist.begin (); |
106 | connection_vector::iterator it = connlist.begin (); |
106 | connection_vector::iterator et = connlist.end (); |
107 | connection_vector::iterator et = connlist.end (); |
107 | int slot; |
108 | int slot; |
… | |
… | |
137 | if (pollfds[slot].revents == 0) |
138 | if (pollfds[slot].revents == 0) |
138 | continue; |
139 | continue; |
139 | if (pollfds[slot].revents & (POLLWRNORM | POLLOUT | POLLHUP | POLLERR)) |
140 | if (pollfds[slot].revents & (POLLWRNORM | POLLOUT | POLLHUP | POLLERR)) |
140 | { |
141 | { |
141 | pollfds[slot].events &= ~(POLLWRNORM | POLLOUT | POLLHUP | POLLERR); |
142 | pollfds[slot].events &= ~(POLLWRNORM | POLLOUT | POLLHUP | POLLERR); |
142 | if (CF_IS_CONNECTING (cptr)) |
143 | if (cptr->is_connecting ()) |
143 | cptr->callback.connected (cptr); |
144 | cptr->callback.connected (cptr); |
144 | else |
145 | else |
145 | cptr->write_handler (cptr); |
146 | cptr->write_handler (cptr); |
146 | } |
147 | } |
147 | } |
148 | } |
148 | |
149 | |
149 | for (it = connlist.begin (), et = connlist.end (); it != et; ++it) |
150 | for (it = connlist.begin (), et = connlist.end (); it != et; ++it) |
150 | { |
151 | { |
151 | connection_t *cptr = *it; |
152 | connection_t *cptr = *it; |
152 | if (cptr->flags & CF_DEAD) |
153 | if (cptr->flags & CF_DEAD) |
153 | connection_close (cptr); |
154 | cptr->close (); |
154 | } |
155 | } |
155 | } |
156 | } |
156 | } |
157 | } |