]>
Commit | Line | Data |
---|---|---|
36aa8c36 JR |
1 | Index: squid3/src/comm_epoll.cc |
2 | diff -c squid3/src/comm_epoll.cc:1.4 squid3/src/comm_epoll.cc:1.5 | |
3 | *** squid3/src/comm_epoll.cc:1.4 Sun Aug 3 15:38:15 2003 | |
4 | --- squid3/src/comm_epoll.cc Sun Nov 9 10:11:10 2003 | |
5 | *************** | |
6 | *** 94,99 **** | |
7 | --- 94,117 ---- | |
8 | } | |
9 | } | |
10 | ||
11 | + static const char* epolltype_atoi(int x) | |
12 | + { | |
13 | + switch(x) { | |
14 | + | |
15 | + case EPOLL_CTL_ADD: | |
16 | + return "EPOLL_CTL_ADD"; | |
17 | + | |
18 | + case EPOLL_CTL_DEL: | |
19 | + return "EPOLL_CTL_DEL"; | |
20 | + | |
21 | + case EPOLL_CTL_MOD: | |
22 | + return "EPOLL_CTL_MOD"; | |
23 | + | |
24 | + default: | |
25 | + return "UNKNOWN_EPOLLCTL_OP"; | |
26 | + } | |
27 | + } | |
28 | + | |
29 | /* | |
30 | * comm_setselect | |
31 | * | |
32 | *************** | |
33 | *** 106,115 **** | |
34 | void *client_data, time_t timeout) | |
35 | { | |
36 | fde *F = &fd_table[fd]; | |
37 | ! int change = 0; | |
38 | ! int events = 0; | |
39 | ! int pollin = 0; | |
40 | ! int pollout = 0; | |
41 | ||
42 | struct epoll_event ev; | |
43 | assert(fd >= 0); | |
44 | --- 124,130 ---- | |
45 | void *client_data, time_t timeout) | |
46 | { | |
47 | fde *F = &fd_table[fd]; | |
48 | ! int epoll_ctl_type = 0; | |
49 | ||
50 | struct epoll_event ev; | |
51 | assert(fd >= 0); | |
52 | *************** | |
53 | *** 117,186 **** | |
54 | debug(5, DEBUG_EPOLL ? 0 : 8) ("commSetSelect(fd=%d,type=%u,handler=%p,client_data=%p,timeout=%ld)\n", | |
55 | fd,type,handler,client_data,timeout); | |
56 | ||
57 | ! if(F->read_handler != NULL) | |
58 | ! pollin = 1; | |
59 | ||
60 | ! if(F->write_handler != NULL) | |
61 | ! pollout = 1; | |
62 | ||
63 | if (type & COMM_SELECT_READ) { | |
64 | ! if(F->read_handler != handler) | |
65 | ! change = 1; | |
66 | ! | |
67 | ! if(handler == NULL) | |
68 | ! pollin = 0; | |
69 | ! else | |
70 | ! pollin = 1; | |
71 | ||
72 | F->read_handler = handler; | |
73 | ||
74 | F->read_data = client_data; | |
75 | } | |
76 | ||
77 | if (type & COMM_SELECT_WRITE) { | |
78 | ! if(F->write_handler != handler) | |
79 | ! change = 1; | |
80 | ! | |
81 | ! if(handler == NULL) | |
82 | ! pollout = 0; | |
83 | ! else | |
84 | ! pollout = 1; | |
85 | ||
86 | F->write_handler = handler; | |
87 | ||
88 | F->write_data = client_data; | |
89 | - } | |
90 | ||
91 | ! if(pollin) | |
92 | ! events |= EPOLLIN; | |
93 | ! | |
94 | ! if(pollout) | |
95 | ! events |= EPOLLOUT; | |
96 | ! | |
97 | ! if(events) | |
98 | ! events |= EPOLLHUP | EPOLLERR; | |
99 | ||
100 | ! ev.data.fd = fd; | |
101 | ||
102 | ! ev.events = events; | |
103 | ||
104 | ! if(events) { | |
105 | ! if (epoll_ctl(kdpfd, EPOLL_CTL_MOD, fd, &ev) < 0) { | |
106 | ! if(errno == ENOENT) { | |
107 | ! debug(5,4) ("commSetSelect: epoll_ctl(,EPOLL_CTL_MOD,,) failed on fd=%d: entry does not exist\n",fd); | |
108 | ||
109 | ! if (epoll_ctl(kdpfd, EPOLL_CTL_ADD, fd, &ev) < 0) | |
110 | ! debug(5,1) ("commSetSelect: cpoll_ctl(,EPOLL_CTL_ADD,,) failed on fd=%d!: %s\n",fd,xstrerror()); | |
111 | ! } else { | |
112 | ! debug(5,1) ("commSetSelect: cpoll_ctl(,EPOLL_CTL_MOD,,) failed on fd=%d!: %s\n",fd,xstrerror()); | |
113 | ! } | |
114 | ! } | |
115 | ! } else if(change) { | |
116 | ! if(epoll_ctl(kdpfd,EPOLL_CTL_DEL,fd,&ev) < 0) { | |
117 | ! if(errno != ENOENT) | |
118 | ! debug(5,1) ("commSetSelect: cpoll_ctl(,EPOLL_CTL_DEL,,) failed on fd=%d!: %s\n",fd,xstrerror()); | |
119 | ! else | |
120 | ! debug(5,4) ("commSetSelect: epoll_ctl(,EPOLL_CTL_DEL,,) failed on fd=%d: entry does not exist\n",fd); | |
121 | } | |
122 | } | |
123 | ||
124 | --- 132,183 ---- | |
125 | debug(5, DEBUG_EPOLL ? 0 : 8) ("commSetSelect(fd=%d,type=%u,handler=%p,client_data=%p,timeout=%ld)\n", | |
126 | fd,type,handler,client_data,timeout); | |
127 | ||
128 | ! ev.events = 0; | |
129 | ! ev.data.fd = fd; | |
130 | ||
131 | ! // If read is an interest | |
132 | ||
133 | if (type & COMM_SELECT_READ) { | |
134 | ! if (handler) | |
135 | ! ev.events |= EPOLLIN; | |
136 | ||
137 | F->read_handler = handler; | |
138 | ||
139 | F->read_data = client_data; | |
140 | + | |
141 | + // Otherwise, use previously stored value | |
142 | + } else if (F->epoll_state & EPOLLIN) { | |
143 | + ev.events |= EPOLLIN; | |
144 | } | |
145 | ||
146 | + // If write is an interest | |
147 | if (type & COMM_SELECT_WRITE) { | |
148 | ! if (handler) | |
149 | ! ev.events |= EPOLLOUT; | |
150 | ||
151 | F->write_handler = handler; | |
152 | ||
153 | F->write_data = client_data; | |
154 | ||
155 | ! // Otherwise, use previously stored value | |
156 | ! } else if (F->epoll_state & EPOLLOUT) { | |
157 | ! ev.events |= EPOLLOUT; | |
158 | ! } | |
159 | ||
160 | ! if (ev.events) | |
161 | ! ev.events |= EPOLLHUP | EPOLLERR; | |
162 | ||
163 | ! if (ev.events != F->epoll_state) { | |
164 | ! if (F->epoll_state) // already monitoring something. | |
165 | ! epoll_ctl_type = ev.events ? EPOLL_CTL_MOD : EPOLL_CTL_DEL; | |
166 | ! else | |
167 | ! epoll_ctl_type = EPOLL_CTL_ADD; | |
168 | ||
169 | ! F->epoll_state = ev.events; | |
170 | ||
171 | ! if (epoll_ctl(kdpfd, epoll_ctl_type, fd, &ev) < 0) { | |
172 | ! debug(5, DEBUG_EPOLL ? 0 : 8) ("commSetSelect: epoll_ctl(,%s,,): failed on fd=%d: %s\n", | |
173 | ! epolltype_atoi(epoll_ctl_type), fd, xstrerror()); | |
174 | } | |
175 | } | |
176 | ||
177 | *************** | |
178 | *** 238,268 **** | |
179 | ||
180 | getCurrentTime(); | |
181 | ||
182 | if (num == 0) | |
183 | ! return COMM_OK; /* No error.. */ | |
184 | ||
185 | for (i = 0, cevents = pevents; i < num; i++, cevents++) { | |
186 | fd = cevents->data.fd; | |
187 | F = &fd_table[fd]; | |
188 | ! debug(5, DEBUG_EPOLL ? 0 : 8) ("comm_select(): got fd=%d events=%d F->read_handler=%p F->write_handler=%p\n", | |
189 | ! fd,cevents->events,F->read_handler,F->write_handler); | |
190 | ||
191 | ! if(cevents->events & (EPOLLIN|EPOLLHUP|EPOLLERR)) { | |
192 | if((hdl = F->read_handler) != NULL) { | |
193 | debug(5, DEBUG_EPOLL ? 0 : 8) ("comm_select(): Calling read handler on fd=%d\n",fd); | |
194 | F->read_handler = NULL; | |
195 | hdl(fd, F->read_data); | |
196 | } | |
197 | } | |
198 | ||
199 | ! if(cevents->events & (EPOLLOUT|EPOLLHUP|EPOLLERR)) { | |
200 | if((hdl = F->write_handler) != NULL) { | |
201 | debug(5, DEBUG_EPOLL ? 0 : 8) ("comm_select(): Calling write handler on fd=%d\n",fd); | |
202 | F->write_handler = NULL; | |
203 | hdl(fd, F->write_data); | |
204 | } | |
205 | } | |
206 | } | |
207 | ||
208 | return COMM_OK; | |
209 | } | |
210 | --- 235,289 ---- | |
211 | ||
212 | getCurrentTime(); | |
213 | ||
214 | + statHistCount(&statCounter.select_fds_hist, num); | |
215 | + | |
216 | if (num == 0) | |
217 | ! return COMM_TIMEOUT; /* No error.. */ | |
218 | ! | |
219 | ! PROF_start(comm_handle_ready_fd); | |
220 | ||
221 | for (i = 0, cevents = pevents; i < num; i++, cevents++) { | |
222 | fd = cevents->data.fd; | |
223 | F = &fd_table[fd]; | |
224 | ! debug(5, DEBUG_EPOLL ? 0 : 8) ("comm_select(): got fd=%d events=%x monitoring=%x F->read_handler=%p F->write_handler=%p\n", | |
225 | ! fd,cevents->events,F->epoll_state,F->read_handler,F->write_handler); | |
226 | ! | |
227 | ! // TODO: add EPOLLPRI?? | |
228 | ||
229 | ! if (cevents->events & (EPOLLIN|EPOLLHUP|EPOLLERR)) { | |
230 | if((hdl = F->read_handler) != NULL) { | |
231 | debug(5, DEBUG_EPOLL ? 0 : 8) ("comm_select(): Calling read handler on fd=%d\n",fd); | |
232 | + PROF_start(comm_write_handler); | |
233 | F->read_handler = NULL; | |
234 | hdl(fd, F->read_data); | |
235 | + PROF_stop(comm_write_handler); | |
236 | + statCounter.select_fds++; | |
237 | + } else { | |
238 | + debug(5, DEBUG_EPOLL ? 0 : 8) ("comm_select(): no read handler for fd=%d\n",fd); | |
239 | + fd_table[fd].flags.read_pending = 1; | |
240 | + // remove interest since no handler exist for this event. | |
241 | + commSetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0); | |
242 | } | |
243 | } | |
244 | ||
245 | ! if (cevents->events & (EPOLLOUT|EPOLLHUP|EPOLLERR)) { | |
246 | if((hdl = F->write_handler) != NULL) { | |
247 | debug(5, DEBUG_EPOLL ? 0 : 8) ("comm_select(): Calling write handler on fd=%d\n",fd); | |
248 | + PROF_start(comm_read_handler); | |
249 | F->write_handler = NULL; | |
250 | hdl(fd, F->write_data); | |
251 | + PROF_stop(comm_read_handler); | |
252 | + statCounter.select_fds++; | |
253 | + } else { | |
254 | + fd_table[fd].flags.write_pending = 1; | |
255 | + debug(5, DEBUG_EPOLL ? 0 : 8) ("comm_select(): no write handler for fd=%d\n",fd); | |
256 | + // remove interest since no handler exist for this event. | |
257 | + commSetSelect(fd, COMM_SELECT_WRITE, NULL, NULL, 0); | |
258 | } | |
259 | } | |
260 | } | |
261 | + | |
262 | + PROF_stop(comm_handle_ready_fd); | |
263 | ||
264 | return COMM_OK; | |
265 | } | |
266 | Index: squid3/src/fd.cc | |
267 | diff -c squid3/src/fd.cc:1.48 squid3/src/fd.cc:1.49 | |
268 | *** squid3/src/fd.cc:1.48 Fri Feb 21 15:50:08 2003 | |
269 | --- squid3/src/fd.cc Sun Nov 9 10:11:11 2003 | |
270 | *************** | |
271 | *** 163,168 **** | |
272 | --- 163,169 ---- | |
273 | debug(51, 3) ("fd_open FD %d %s\n", fd, desc); | |
274 | F->type = type; | |
275 | F->flags.open = 1; | |
276 | + F->epoll_state = 0; | |
277 | #ifdef _SQUID_MSWIN_ | |
278 | ||
279 | switch (type) { | |
280 | Index: squid3/src/fde.h | |
281 | diff -c squid3/src/fde.h:1.5 squid3/src/fde.h:1.6 | |
282 | *** squid3/src/fde.h:1.5 Tue Jul 15 00:50:42 2003 | |
283 | --- squid3/src/fde.h Sun Nov 9 10:11:11 2003 | |
284 | *************** | |
285 | *** 93,104 **** | |
286 | --- 93,108 ---- | |
287 | ||
288 | unsigned int read_pending: | |
289 | 1; | |
290 | + | |
291 | + unsigned int write_pending: | |
292 | + 1; | |
293 | } | |
294 | ||
295 | flags; | |
296 | int bytes_read; | |
297 | int bytes_written; | |
298 | int uses; /* ie # req's over persistent conn */ | |
299 | + unsigned epoll_state; | |
300 | ||
301 | struct _fde_disk disk; | |
302 | PF *read_handler; |