1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
| | /*
* Copyright (C) 2012-2013, Eric Wong <normalperson@yhbt.net>
* License: GPLv3 or later (see COPYING for details)
*/
#include "cmogstored.h"
/*
* access to this should only be called in the main thread, this
* is currently not thread safe as there's no need for it.
*/
static LIST_HEAD(all_queues);
struct mog_queue *mog_queue_init(int queue_fd)
{
struct mog_fd *mfd;
struct mog_queue *q;
/*
* Do not bother with epoll_create1(EPOLL_CLOEXEC),
* there's no kqueue version of it. We only create epoll/kqueue
* descriptors before we'd ever fork anything
*/
CHECK(int, 0, mog_set_cloexec(queue_fd, true));
mfd = mog_fd_init(queue_fd, MOG_FD_TYPE_QUEUE);
q = &mfd->as.queue;
q->queue_fd = queue_fd;
memset(&q->thrpool, 0, sizeof(struct mog_thrpool));
list_add(&all_queues, &q->qbuddies);
return q;
}
void mog_queue_stop(struct mog_queue *keep)
{
struct mog_queue *queue, *tmp;
struct mog_fd *mfd;
list_for_each_safe(&all_queues, queue, tmp, qbuddies) {
/* keep is usually mog_notify_queue */
if (queue == keep)
continue;
list_del(&queue->qbuddies);
mog_thrpool_quit(&queue->thrpool, queue);
mfd = mog_fd_of(queue);
mog_fd_put(mfd);
}
}
void mog_queue_drop(struct mog_fd *mfd)
{
switch (mfd->fd_type) {
case MOG_FD_TYPE_HTTP:
case MOG_FD_TYPE_HTTPGET:
mog_http_drop(mfd);
return;
case MOG_FD_TYPE_MGMT:
mog_mgmt_drop(mfd);
return;
default:
syslog(LOG_ERR,
"dropping fd_type=%d, functionality may be compromised",
mfd->fd_type);
mog_fd_put(mfd);
}
}
|