Per-tube buried list; kick takes tube name.
[beanstalkd.git] / conn.h
blob2a277bb00eb16822f1e556e1dc2a74df5689bc21
1 /* conn.h - network connection state */
3 /* Copyright (C) 2007 Keith Rarick and Philotic Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef conn_h
20 #define conn_h
22 #include "event.h"
23 #include "ms.h"
24 #include "tube.h"
25 #include "job.h"
27 #define STATE_WANTCOMMAND 0
28 #define STATE_WANTDATA 1
29 #define STATE_SENDJOB 2
30 #define STATE_SENDWORD 3
31 #define STATE_WAIT 4
33 /* A command can be at most LINE_BUF_SIZE chars, including "\r\n". This value
34 * MUST be enough to hold the longest possible command or reply line, which is
35 * currently "release 18446744073709551615 4294967295 4294967295\r\n". */
36 #define LINE_BUF_SIZE 54
38 #define OP_UNKNOWN 0
39 #define OP_PUT 1
40 #define OP_PEEKJOB 2
41 #define OP_RESERVE 3
42 #define OP_DELETE 4
43 #define OP_RELEASE 5
44 #define OP_BURY 6
45 #define OP_KICK 7
46 #define OP_STATS 8
47 #define OP_JOBSTATS 9
48 #define OP_PEEK 10
49 #define OP_USE 11
50 #define OP_WATCH 12
51 #define OP_IGNORE 13
52 #define OP_LIST_TUBES 14
53 #define OP_LIST_TUBES_WATCHED 15
54 #define OP_STATS_TUBE 16
56 /* CONN_TYPE_* are bit masks */
57 #define CONN_TYPE_PRODUCER 1
58 #define CONN_TYPE_WORKER 2
59 #define CONN_TYPE_WAITING 4
61 typedef struct conn *conn;
63 struct conn {
64 conn prev, next; /* linked list of connections */
65 int fd;
66 char state;
67 char type;
68 struct event evq;
70 /* we cannot share this buffer with the reply line because we might read in
71 * command line data for a subsequent command, and we need to store it
72 * here. */
73 char cmd[LINE_BUF_SIZE]; /* this string is NOT NUL-terminated */
74 int cmd_len;
75 int cmd_read;
76 const char *reply;
77 int reply_len;
78 int reply_sent;
79 char reply_buf[LINE_BUF_SIZE]; /* this string IS NUL-terminated */
80 job in_job;
81 int in_job_read;
82 job out_job;
83 int out_job_sent;
84 struct job reserved_jobs; /* doubly-linked list header */
85 tube use;
86 struct ms watch;
89 conn make_conn(int fd, char start_state, tube use, tube watch);
91 int conn_set_evq(conn c, const int events, evh handler);
92 int conn_update_evq(conn c, const int flags);
94 void conn_close(conn c);
96 conn conn_remove(conn c);
97 void conn_insert(conn head, conn c);
99 int count_cur_conns();
100 unsigned int count_tot_conns();
101 int count_cur_producers();
102 int count_cur_workers();
104 void conn_set_producer(conn c);
105 void conn_set_worker(conn c);
107 job soonest_job(conn c);
108 int has_reserved_this_job(conn c, job j);
110 #endif /*conn_h*/