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/>.
27 #define STATE_WANTCOMMAND 0
28 #define STATE_WANTDATA 1
29 #define STATE_SENDJOB 2
30 #define STATE_SENDWORD 3
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 "USING a{200}\r\n". */
36 #define LINE_BUF_SIZE 208
52 #define OP_LIST_TUBES 14
53 #define OP_LIST_TUBE_USED 15
54 #define OP_LIST_TUBES_WATCHED 16
55 #define OP_STATS_TUBE 17
57 /* CONN_TYPE_* are bit masks */
58 #define CONN_TYPE_PRODUCER 1
59 #define CONN_TYPE_WORKER 2
60 #define CONN_TYPE_WAITING 4
62 #define conn_waiting(c) ((c)->type & CONN_TYPE_WAITING)
64 typedef struct conn
*conn
;
67 conn prev
, next
; /* linked list of connections */
73 /* we cannot share this buffer with the reply line because we might read in
74 * command line data for a subsequent command, and we need to store it
76 char cmd
[LINE_BUF_SIZE
]; /* this string is NOT NUL-terminated */
82 char reply_buf
[LINE_BUF_SIZE
]; /* this string IS NUL-terminated */
87 struct job reserved_jobs
; /* doubly-linked list header */
92 conn
make_conn(int fd
, char start_state
, tube use
, tube watch
);
94 int conn_set_evq(conn c
, const int events
, evh handler
);
95 int conn_update_evq(conn c
, const int flags
);
97 void conn_close(conn c
);
99 conn
conn_remove(conn c
);
100 void conn_insert(conn head
, conn c
);
102 int count_cur_conns();
103 unsigned int count_tot_conns();
104 int count_cur_producers();
105 int count_cur_workers();
107 void conn_set_producer(conn c
);
108 void conn_set_worker(conn c
);
110 job
soonest_job(conn c
);
111 int has_reserved_this_job(conn c
, job j
);
112 int conn_has_close_deadline(conn c
);
113 int conn_ready(conn c
);