Skip to content
This repository was archived by the owner on Jan 6, 2023. It is now read-only.

Commit 1cf932a

Browse files
committed
introduce CONTROL_HEADER_SIZE & CONTROL_HEADER_LENGTH_OFFSET
Signed-off-by: Lai Jiangshan <[email protected]>
1 parent 5c30a49 commit 1cf932a

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/api.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#define APIVERSION 4242
55

6+
// control command id
67
enum {
78
GETVERSION,
89
STARTPOD,
@@ -29,6 +30,15 @@ enum {
2930
REMOVECONTAINER,
3031
};
3132

33+
/*
34+
* control message format
35+
* | ctrl id | length | payload (length-8) |
36+
* | . . . . | . . . . | . . . . . . . . . . . . |
37+
* 0 4 8 length
38+
*/
39+
#define CONTROL_HEADER_SIZE 8
40+
#define CONTROL_HEADER_LENGTH_OFFSET 4
41+
3242
/*
3343
* stream message format
3444
* | stream sequence | length | payload (length-12) |

src/init.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,15 +1179,15 @@ static int hyper_channel_handle(struct hyper_event *de, uint32_t len)
11791179
static int hyper_channel_read(struct hyper_event *he, int efd)
11801180
{
11811181
struct hyper_buf *buf = &he->rbuf;
1182-
uint32_t len = he->ops->len_offset + 4;
1182+
uint32_t len;
11831183
uint8_t data[4];
11841184
int size;
11851185
int ret;
11861186

11871187
fprintf(stdout, "%s\n", __func__);
11881188

1189-
if (buf->get < len) {
1190-
size = nonblock_read(he->fd, buf->data + buf->get, len - buf->get);
1189+
if (buf->get < CONTROL_HEADER_SIZE) {
1190+
size = nonblock_read(he->fd, buf->data + buf->get, CONTROL_HEADER_SIZE - buf->get);
11911191
if (size < 0) {
11921192
return size;
11931193
}
@@ -1197,12 +1197,12 @@ static int hyper_channel_read(struct hyper_event *he, int efd)
11971197
hyper_send_msg(he->fd, NEXT, 4, data);
11981198
}
11991199
buf->get += size;
1200-
if (buf->get < len) {
1200+
if (buf->get < CONTROL_HEADER_SIZE) {
12011201
return 0;
12021202
}
12031203
}
12041204

1205-
hyper_getmsg_len(he, &len);
1205+
len = hyper_get_be32(buf->data + CONTROL_HEADER_LENGTH_OFFSET);
12061206
fprintf(stdout, "get length %" PRIu32"\n", len);
12071207
// test it with '>=' to leave at least one byte in hyper_channel_handle(),
12081208
// so that hyper_channel_handle() can convert the data to c-string inplace.

0 commit comments

Comments
 (0)