forked from nsqio/libnsq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.c
49 lines (39 loc) · 1017 Bytes
/
command.c
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
#include <stdio.h>
#include <evbuffsock.h>
const static char * NEW_LINE = "\n";
const static int MAX_BUF_SIZE = 128;
void nsq_subscribe(struct Buffer *buf, const char *topic, const char *channel)
{
char b[MAX_BUF_SIZE];
size_t n;
n = sprintf(b, "SUB %s %s%s", topic, channel, NEW_LINE);
buffer_add(buf, b, n);
}
void nsq_ready(struct Buffer *buf, int count)
{
char b[MAX_BUF_SIZE];
size_t n;
n = sprintf(b, "RDY %d%s", count, NEW_LINE);
buffer_add(buf, b, n);
}
void nsq_finish(struct Buffer *buf, const char *id)
{
char b[MAX_BUF_SIZE];
size_t n;
n = sprintf(b, "FIN %s%s", id, NEW_LINE);
buffer_add(buf, b, n);
}
void nsq_requeue(struct Buffer *buf, const char *id, int timeout_ms)
{
char b[MAX_BUF_SIZE];
size_t n;
n = sprintf(b, "REQ %s %d%s", id, timeout_ms, NEW_LINE);
buffer_add(buf, b, n);
}
void nsq_nop(struct Buffer *buf)
{
char b[MAX_BUF_SIZE];
size_t n;
n = sprintf(b, "NOP%s", NEW_LINE);
buffer_add(buf, b, n);
}