/*
- * $Id: comm_kqueue.cc,v 1.3 2002/10/13 20:35:00 robertc Exp $
+ * $Id: comm_kqueue.cc,v 1.4 2002/10/27 13:06:49 adrian Exp $
*
* DEBUG: section 5 Socket functions
*
#include <sys/event.h>
-#define KE_LENGTH 128
+#define KE_LENGTH 128
/* jlemon goofed up and didn't add EV_SET until fbsd 4.3 */
static int kq;
static struct timespec zero_timespec;
-static struct kevent *kqlst; /* kevent buffer */
-static int kqmax; /* max structs to buffer */
-static int kqoff; /* offset into the buffer */
+static struct kevent *kqlst; /* kevent buffer */
+static int kqmax; /* max structs to buffer */
+static int kqoff; /* offset into the buffer */
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
switch (filter) {
case EVFILT_READ:
- cur_handler = fd_table[fd].read_handler;
- break;
+ cur_handler = fd_table[fd].read_handler;
+ break;
case EVFILT_WRITE:
- cur_handler = fd_table[fd].write_handler;
- break;
+ cur_handler = fd_table[fd].write_handler;
+ break;
default:
- /* XXX bad! -- adrian */
- return;
- break;
+ /* XXX bad! -- adrian */
+ return;
+ break;
}
if ((cur_handler == NULL && handler != NULL)
- || (cur_handler != NULL && handler == NULL)) {
- struct kevent *kep;
-
- kep = kqlst + kqoff;
-
- if (handler != NULL) {
- kep_flags = (EV_ADD | EV_ONESHOT);
- } else {
- kep_flags = EV_DELETE;
- }
-
- EV_SET(kep, (uintptr_t) fd, filter, kep_flags, 0, 0, 0);
-
- if (kqoff == kqmax) {
- int ret;
-
- ret = kevent(kq, kqlst, kqoff, NULL, 0, &zero_timespec);
- /* jdc -- someone needs to do error checking... */
- if (ret == -1) {
- perror("kq_update_events(): kevent()");
- return;
- }
- kqoff = 0;
- } else {
- kqoff++;
- }
+ || (cur_handler != NULL && handler == NULL)) {
+ struct kevent *kep;
+
+ kep = kqlst + kqoff;
+
+ if (handler != NULL) {
+ kep_flags = (EV_ADD | EV_ONESHOT);
+ } else {
+ kep_flags = EV_DELETE;
+ }
+
+ EV_SET(kep, (uintptr_t) fd, filter, kep_flags, 0, 0, 0);
+
+ if (kqoff == kqmax) {
+ int ret;
+
+ ret = kevent(kq, kqlst, kqoff, NULL, 0, &zero_timespec);
+ /* jdc -- someone needs to do error checking... */
+ if (ret == -1) {
+ perror("kq_update_events(): kevent()");
+ return;
+ }
+ kqoff = 0;
+ } else {
+ kqoff++;
+ }
#if 0
- if (retval < 0) {
- /* Error! */
- if (ke.flags & EV_ERROR) {
- errno = ke.data;
- }
- }
+ if (retval < 0) {
+ /* Error! */
+ if (ke.flags & EV_ERROR) {
+ errno = ke.data;
+ }
+ }
#endif
}
}
{
kq = kqueue();
if (kq < 0) {
- fatal("comm_select_init: Couldn't open kqueue fd!\n");
+ fatal("comm_select_init: Couldn't open kqueue fd!\n");
}
kqmax = getdtablesize();
kqlst = xmalloc(sizeof(*kqlst) * kqmax);
assert(F->flags.open);
if (type & COMM_SELECT_READ) {
- kq_update_events(fd, EVFILT_READ, handler);
- F->read_handler = handler;
- F->read_data = client_data;
+ kq_update_events(fd, EVFILT_READ, handler);
+ F->read_handler = handler;
+ F->read_data = client_data;
}
if (type & COMM_SELECT_WRITE) {
- kq_update_events(fd, EVFILT_WRITE, handler);
- F->write_handler = handler;
- F->write_data = client_data;
+ kq_update_events(fd, EVFILT_WRITE, handler);
+ F->write_handler = handler;
+ F->write_data = client_data;
}
if (timeout)
- F->timeout = squid_curtime + timeout;
+ F->timeout = squid_curtime + timeout;
}
struct timespec poll_time;
do {
- /*
- * remember we are doing NANOseconds here, not micro/milli. God knows
- * why jlemon used a timespec, but hey, he wrote the interface, not I
- * -- Adrian
- */
- poll_time.tv_sec = msec / 1000;
- poll_time.tv_nsec = (msec % 1000) * 1000000;
- for (;;) {
- num = kevent(kq, kqlst, kqoff, ke, KE_LENGTH, &poll_time);
- statCounter.select_loops++;
- kqoff = 0;
- if (num >= 0)
- break;
- if (ignoreErrno(errno))
- break;
- getCurrentTime();
- return COMM_ERROR;
- /* NOTREACHED */
- }
-
- getCurrentTime();
- if (num == 0)
- continue;
-
- for (i = 0; i < num; i++) {
- int fd = (int) ke[i].ident;
- PF *hdl = NULL;
- fde *F = &fd_table[fd];
-
- if (ke[i].flags & EV_ERROR) {
- errno = ke[i].data;
- /* XXX error == bad! -- adrian */
- continue; /* XXX! */
- }
- switch (ke[i].filter) {
- case EVFILT_READ:
- if ((hdl = F->read_handler) != NULL) {
- F->read_handler = NULL;
- hdl(fd, F->read_data);
- }
- case EVFILT_WRITE:
- if ((hdl = F->write_handler) != NULL) {
- F->write_handler = NULL;
- hdl(fd, F->write_data);
- }
- default:
- /* Bad! -- adrian */
- break;
- }
- }
- return COMM_OK;
+ /*
+ * remember we are doing NANOseconds here, not micro/milli. God knows
+ * why jlemon used a timespec, but hey, he wrote the interface, not I
+ * -- Adrian
+ */
+ poll_time.tv_sec = msec / 1000;
+ poll_time.tv_nsec = (msec % 1000) * 1000000;
+ for (;;) {
+ num = kevent(kq, kqlst, kqoff, ke, KE_LENGTH, &poll_time);
+ statCounter.select_loops++;
+ kqoff = 0;
+ if (num >= 0)
+ break;
+ if (ignoreErrno(errno))
+ break;
+ getCurrentTime();
+ return COMM_ERROR;
+ /* NOTREACHED */
+ }
+
+ getCurrentTime();
+ if (num == 0)
+ continue;
+
+ for (i = 0; i < num; i++) {
+ int fd = (int) ke[i].ident;
+ PF *hdl = NULL;
+ fde *F = &fd_table[fd];
+
+ if (ke[i].flags & EV_ERROR) {
+ errno = ke[i].data;
+ /* XXX error == bad! -- adrian */
+ continue; /* XXX! */
+ }
+ switch (ke[i].filter) {
+ case EVFILT_READ:
+ if ((hdl = F->read_handler) != NULL) {
+ F->read_handler = NULL;
+ hdl(fd, F->read_data);
+ }
+ case EVFILT_WRITE:
+ if ((hdl = F->write_handler) != NULL) {
+ F->write_handler = NULL;
+ hdl(fd, F->write_data);
+ }
+ default:
+ /* Bad! -- adrian */
+ break;
+ }
+ }
+ return COMM_OK;
}
- while (0); /* XXX should rip this out! -- adrian */
+ while (0); /* XXX should rip this out! -- adrian */
/* XXX Get here, we broke! */
return 0;
}