void vca_close_session(struct sess *sp, const char *why);
void VCA_Prep(struct sess *sp);
void VCA_Init(void);
+extern int vca_pipes[2];
/* cache_backend.c */
void VBE_Init(void);
static unsigned char need_sndtimeo, need_rcvtimeo, need_linger, need_test;
+int vca_pipes[2];
+
static void
sock_test(int fd)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
AZ(sp->obj);
AZ(sp->vcl);
- vca_act->recycle(sp);
+ if (sp->fd < 0)
+ SES_Delete(sp);
+ else
+ assert(sizeof sp == write(vca_pipes[1], &sp, sizeof sp));
}
fprintf(stderr, "No acceptor in program\n");
exit (2);
}
+ AZ(pipe(vca_pipes));
vca_act->init();
AZ(pthread_create(&vca_thread_acct, NULL, vca_acct, NULL));
}
struct sess;
typedef void acceptor_init_f(void);
-typedef void acceptor_recycle_f(struct sess *);
struct acceptor {
const char *name;
acceptor_init_f *init;
- acceptor_recycle_f *recycle;
};
#if defined(HAVE_EPOLL_CTL)
static pthread_t vca_epoll_thread;
static int epfd = -1;
-static int pipes[2];
static TAILQ_HEAD(,sess) sesshead = TAILQ_HEAD_INITIALIZER(sesshead);
epfd = epoll_create(16);
assert(epfd >= 0);
- vca_add(pipes[0], pipes);
+ vca_add(vca_pipes[0], vca_pipes);
while (1) {
if (epoll_wait(epfd, &ev, 1, 100) > 0) {
- if (ev.data.ptr == pipes) {
- i = read(pipes[0], &sp, sizeof sp);
+ if (ev.data.ptr == vca_pipes) {
+ i = read(vca_pipes[0], &sp, sizeof sp);
assert(i == sizeof sp);
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
TAILQ_INSERT_TAIL(&sesshead, sp, list);
/*--------------------------------------------------------------------*/
-static void
-vca_epoll_recycle(struct sess *sp)
-{
-
- if (sp->fd < 0)
- SES_Delete(sp);
- else
- assert(sizeof sp == write(pipes[1], &sp, sizeof sp));
-}
-
static void
vca_epoll_init(void)
{
- AZ(pipe(pipes));
AZ(pthread_create(&vca_epoll_thread, NULL, vca_main, NULL));
}
struct acceptor acceptor_epoll = {
.name = "epoll",
.init = vca_epoll_init,
- .recycle = vca_epoll_recycle,
};
#endif /* defined(HAVE_EPOLL_CTL) */
static int kq = -1;
static TAILQ_HEAD(,sess) sesshead = TAILQ_HEAD_INITIALIZER(sesshead);
-static int pipes[2];
#define NKEV 100
struct sess *ss[NKEV];
AN(kp->udata);
- if (kp->udata == pipes) {
+ if (kp->udata == vca_pipes) {
j = 0;
- i = read(pipes[0], ss, sizeof ss);
+ i = read(vca_pipes[0], ss, sizeof ss);
if (i == -1 && errno == EAGAIN)
return;
while (i >= sizeof ss[0]) {
j = 0;
EV_SET(&ke[j++], 0, EVFILT_TIMER, EV_ADD, 0, 100, NULL);
- EV_SET(&ke[j++], pipes[0], EVFILT_READ, EV_ADD, 0, 0, pipes);
+ EV_SET(&ke[j++], vca_pipes[0], EVFILT_READ, EV_ADD, 0, 0, vca_pipes);
AZ(kevent(kq, ke, j, NULL, 0, NULL));
nki = 0;
/*--------------------------------------------------------------------*/
-static void
-vca_kqueue_recycle(struct sess *sp)
-{
-
- if (sp->fd < 0)
- SES_Delete(sp);
- else
- assert(write(pipes[1], &sp, sizeof sp) == sizeof sp);
-}
-
static void
vca_kqueue_init(void)
{
int i;
- AZ(pipe(pipes));
- i = fcntl(pipes[0], F_GETFL);
+ i = fcntl(vca_pipes[0], F_GETFL);
i |= O_NONBLOCK;
- i = fcntl(pipes[0], F_SETFL, i);
+ i = fcntl(vca_pipes[0], F_SETFL, i);
AZ(pthread_create(&vca_kqueue_thread, NULL, vca_kqueue_main, NULL));
}
struct acceptor acceptor_kqueue = {
.name = "kqueue",
.init = vca_kqueue_init,
- .recycle = vca_kqueue_recycle,
};
#endif /* defined(HAVE_KQUEUE) */
static struct pollfd *pollfd;
static unsigned npoll;
-static int pipes[2];
-
static TAILQ_HEAD(,sess) sesshead = TAILQ_HEAD_INITIALIZER(sesshead);
/*--------------------------------------------------------------------*/
(void)arg;
- vca_poll(pipes[0]);
+ vca_poll(vca_pipes[0]);
while (1) {
v = poll(pollfd, npoll, 100);
- if (v && pollfd[pipes[0]].revents) {
+ if (v && pollfd[vca_pipes[0]].revents) {
v--;
- i = read(pipes[0], &sp, sizeof sp);
+ i = read(vca_pipes[0], &sp, sizeof sp);
assert(i == sizeof sp);
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
TAILQ_INSERT_TAIL(&sesshead, sp, list);
/*--------------------------------------------------------------------*/
-static void
-vca_poll_recycle(struct sess *sp)
-{
-
- if (sp->fd < 0)
- SES_Delete(sp);
- else
- assert(sizeof sp == write(pipes[1], &sp, sizeof sp));
-}
-
static void
vca_poll_init(void)
{
- AZ(pipe(pipes));
+
AZ(pthread_create(&vca_poll_thread, NULL, vca_main, NULL));
}
struct acceptor acceptor_poll = {
.name = "poll",
.init = vca_poll_init,
- .recycle = vca_poll_recycle,
};
#endif /* defined(HAVE_POLL) */