0
@@ -50,6 +50,7 @@ size_t job_data_size_limit = ((1 << 16) - 1);
0
#define CMD_PEEK_DELAYED "peek-delayed"
0
#define CMD_PEEK_BURIED "peek-buried"
0
#define CMD_RESERVE "reserve"
0
+#define CMD_RESERVE_TIMEOUT "reserve-with-timeout "
0
#define CMD_DELETE "delete "
0
#define CMD_RELEASE "release "
0
#define CMD_BURY "bury "
0
@@ -71,6 +72,7 @@ size_t job_data_size_limit = ((1 << 16) - 1);
0
#define CMD_PEEK_BURIED_LEN CONSTSTRLEN(CMD_PEEK_BURIED)
0
#define CMD_PEEKJOB_LEN CONSTSTRLEN(CMD_PEEKJOB)
0
#define CMD_RESERVE_LEN CONSTSTRLEN(CMD_RESERVE)
0
+#define CMD_RESERVE_TIMEOUT_LEN CONSTSTRLEN(CMD_RESERVE_TIMEOUT)
0
#define CMD_DELETE_LEN CONSTSTRLEN(CMD_DELETE)
0
#define CMD_RELEASE_LEN CONSTSTRLEN(CMD_RELEASE)
0
#define CMD_BURY_LEN CONSTSTRLEN(CMD_BURY)
0
@@ -89,6 +91,7 @@ size_t job_data_size_limit = ((1 << 16) - 1);
0
#define MSG_NOTFOUND "NOT_FOUND\r\n"
0
#define MSG_RESERVED "RESERVED"
0
#define MSG_DEADLINE_SOON "DEADLINE_SOON\r\n"
0
+#define MSG_TIMED_OUT "TIMED_OUT\r\n"
0
#define MSG_DELETED "DELETED\r\n"
0
#define MSG_RELEASED "RELEASED\r\n"
0
#define MSG_BURIED "BURIED\r\n"
0
@@ -137,7 +140,8 @@ size_t job_data_size_limit = ((1 << 16) - 1);
0
#define OP_STATS_TUBE 17
0
#define OP_PEEK_READY 18
0
#define OP_PEEK_DELAYED 19
0
+#define OP_RESERVE_TIMEOUT 20
0
#define STATS_FMT "---\n" \
0
"current-jobs-urgent: %u\n" \
0
@@ -151,6 +155,7 @@ size_t job_data_size_limit = ((1 << 16) - 1);
0
"cmd-peek-delayed: %llu\n" \
0
"cmd-peek-buried: %llu\n" \
0
"cmd-reserve: %llu\n" \
0
+ "cmd-reserve-with-timeout: %llu\n" \
0
"cmd-release: %llu\n" \
0
@@ -704,6 +709,7 @@ which_cmd(conn c)
0
TEST_CMD(c->cmd, CMD_PEEK_READY, OP_PEEK_READY);
0
TEST_CMD(c->cmd, CMD_PEEK_DELAYED, OP_PEEK_DELAYED);
0
TEST_CMD(c->cmd, CMD_PEEK_BURIED, OP_PEEK_BURIED);
0
+ TEST_CMD(c->cmd, CMD_RESERVE_TIMEOUT, OP_RESERVE_TIMEOUT);
0
TEST_CMD(c->cmd, CMD_RESERVE, OP_RESERVE);
0
TEST_CMD(c->cmd, CMD_DELETE, OP_DELETE);
0
TEST_CMD(c->cmd, CMD_RELEASE, OP_RELEASE);
0
@@ -809,6 +815,7 @@ fmt_stats(char *buf, size_t size, void *x)
0
op_ct[OP_PEEK_DELAYED],
0
+ op_ct[OP_RESERVE_TIMEOUT],
0
@@ -882,13 +889,16 @@ read_ttr(unsigned int *ttr, const char *buf, char **end)
0
+wait_for_job(conn c
, int timeout)
0
enqueue_waiting_conn(c);
0
+ /* Set the pending timeout to the requested timeout amount */
0
+ c->pending_timeout = timeout;
0
/* this conn is waiting, but we want to know if they hang up */
0
r = conn_update_evq(c, EV_READ | EV_PERSIST);
0
if (r == -1) return twarnx("update events failed"), conn_close(c);
0
@@ -1068,7 +1078,7 @@ find_or_make_tube(const char *name)
0
+ int r, i
, timeout = -1;
0
@@ -1189,9 +1199,13 @@ dispatch_cmd(conn c)
0
reply_job(c, j, MSG_FOUND);
0
+ case OP_RESERVE_TIMEOUT:
0
+ timeout = strtol(c->cmd + CMD_RESERVE_TIMEOUT_LEN, &end_buf, 10);
0
+ if (errno) return reply_msg(c, MSG_BAD_FORMAT);
0
+ case OP_RESERVE: /* FALLTHROUGH */
0
/* don't allow trailing garbage */
0
- if (
c->cmd_len != CMD_RESERVE_LEN + 2) {
0
+ if (
type == OP_RESERVE && c->cmd_len != CMD_RESERVE_LEN + 2) {
0
return reply_msg(c, MSG_BAD_FORMAT);
0
@@ -1203,7 +1217,7 @@ dispatch_cmd(conn c)
0
/* try to get a new job for this guy */
0
+ wait_for_job(c
, timeout);
0
@@ -1415,6 +1429,10 @@ h_conn_timeout(conn c)
0
dprintf("conn_waiting(%p) = %d\n", c, conn_waiting(c));
0
return reply_msg(remove_waiting_conn(c), MSG_DEADLINE_SOON);
0
+ } else if (conn_waiting(c) && c->pending_timeout >= 0) {
0
+ dprintf("conn_waiting(%p) = %d\n", c, conn_waiting(c));
0
+ c->pending_timeout=-1;
0
+ return reply_msg(remove_waiting_conn(c), MSG_TIMED_OUT);
Comments
No one has commented yet.