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
11 + static const char* epolltype_atoi(int x)
16 + return "EPOLL_CTL_ADD";
19 + return "EPOLL_CTL_DEL";
22 + return "EPOLL_CTL_MOD";
25 + return "UNKNOWN_EPOLLCTL_OP";
34 void *client_data, time_t timeout)
36 fde *F = &fd_table[fd];
42 struct epoll_event ev;
45 void *client_data, time_t timeout)
47 fde *F = &fd_table[fd];
48 ! int epoll_ctl_type = 0;
50 struct epoll_event ev;
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);
57 ! if(F->read_handler != NULL)
60 ! if(F->write_handler != NULL)
63 if (type & COMM_SELECT_READ) {
64 ! if(F->read_handler != handler)
72 F->read_handler = handler;
74 F->read_data = client_data;
77 if (type & COMM_SELECT_WRITE) {
78 ! if(F->write_handler != handler)
86 F->write_handler = handler;
88 F->write_data = client_data;
98 ! events |= EPOLLHUP | EPOLLERR;
102 ! ev.events = 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);
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());
112 ! debug(5,1) ("commSetSelect: cpoll_ctl(,EPOLL_CTL_MOD,,) failed on fd=%d!: %s\n",fd,xstrerror());
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());
120 ! debug(5,4) ("commSetSelect: epoll_ctl(,EPOLL_CTL_DEL,,) failed on fd=%d: entry does not exist\n",fd);
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);
131 ! // If read is an interest
133 if (type & COMM_SELECT_READ) {
135 ! ev.events |= EPOLLIN;
137 F->read_handler = handler;
139 F->read_data = client_data;
141 + // Otherwise, use previously stored value
142 + } else if (F->epoll_state & EPOLLIN) {
143 + ev.events |= EPOLLIN;
146 + // If write is an interest
147 if (type & COMM_SELECT_WRITE) {
149 ! ev.events |= EPOLLOUT;
151 F->write_handler = handler;
153 F->write_data = client_data;
155 ! // Otherwise, use previously stored value
156 ! } else if (F->epoll_state & EPOLLOUT) {
157 ! ev.events |= EPOLLOUT;
161 ! ev.events |= EPOLLHUP | EPOLLERR;
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;
167 ! epoll_ctl_type = EPOLL_CTL_ADD;
169 ! F->epoll_state = ev.events;
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());
183 ! return COMM_OK; /* No error.. */
185 for (i = 0, cevents = pevents; i < num; i++, cevents++) {
186 fd = cevents->data.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);
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);
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);
214 + statHistCount(&statCounter.select_fds_hist, num);
217 ! return COMM_TIMEOUT; /* No error.. */
219 ! PROF_start(comm_handle_ready_fd);
221 for (i = 0, cevents = pevents; i < num; i++, cevents++) {
222 fd = cevents->data.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);
227 ! // TODO: add EPOLLPRI??
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++;
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);
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++;
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);
262 + PROF_stop(comm_handle_ready_fd);
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
273 debug(51, 3) ("fd_open FD %d %s\n", fd, desc);
276 + F->epoll_state = 0;
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
288 unsigned int read_pending:
291 + unsigned int write_pending:
298 int uses; /* ie # req's over persistent conn */
299 + unsigned epoll_state;
301 struct _fde_disk disk;