Make peek show next delayed job (#919).
[beanstalkd.git] / conn.h
blobe1cc5bd88a0dbbe56481ef2ecef6cd67f73b1a1f
1 /* conn.h - network connection state */
3 #ifndef conn_h
4 #define conn_h
6 #include "event.h"
7 #include "job.h"
9 #define STATE_WANTCOMMAND 0
10 #define STATE_WANTDATA 1
11 #define STATE_SENDJOB 2
12 #define STATE_SENDWORD 3
13 #define STATE_WAIT 4
15 /* A command can be at most LINE_BUF_SIZE chars, including "\r\n". This value
16 * MUST be enough to hold the longest possible command or reply line, which is
17 * currently "release 18446744073709551615 4294967295 4294967295\r\n". */
18 #define LINE_BUF_SIZE 54
20 #define OP_UNKNOWN -1
21 #define OP_PUT 0
22 #define OP_PEEKJOB 1
23 #define OP_RESERVE 2
24 #define OP_DELETE 3
25 #define OP_RELEASE 4
26 #define OP_BURY 5
27 #define OP_KICK 6
28 #define OP_STATS 7
29 #define OP_JOBSTATS 8
30 #define OP_PEEK 9
32 /* CONN_TYPE_* are bit masks */
33 #define CONN_TYPE_PRODUCER 1
34 #define CONN_TYPE_WORKER 2
35 #define CONN_TYPE_WAITING 4
37 typedef struct conn *conn;
39 struct conn {
40 conn prev, next; /* linked list of connections */
41 int fd;
42 char state;
43 char type;
44 struct event evq;
46 /* we cannot share this buffer with the reply line because we might read in
47 * command line data for a subsequent command, and we need to store it
48 * here. */
49 char cmd[LINE_BUF_SIZE]; /* this string is NOT NUL-terminated */
50 int cmd_len;
51 int cmd_read;
52 char *reply;
53 int reply_len;
54 int reply_sent;
55 char reply_buf[LINE_BUF_SIZE]; /* this string IS NUL-terminated */
56 job in_job;
57 int in_job_read;
58 job out_job;
59 int out_job_sent;
60 struct job reserved_jobs; /* doubly-linked list header */
63 void conn_init();
65 conn make_conn(int fd, char start_state);
67 int conn_set_evq(conn c, const int events, evh handler);
68 int conn_update_evq(conn c, const int flags);
70 void conn_close(conn c);
72 int conn_list_any_p(conn head);
73 conn conn_remove(conn c);
74 void conn_insert(conn head, conn c);
76 int count_cur_conns();
77 unsigned int count_tot_conns();
78 int count_cur_producers();
79 int count_cur_workers();
81 void conn_set_producer(conn c);
82 void conn_set_worker(conn c);
84 #endif /*conn_h*/