introduce CONTROL_HEADER_SIZE & CONTROL_HEADER_LENGTH_OFFSET

Signed-off-by: Lai Jiangshan <jiangshanlai@gmail.com>
This commit is contained in:
Lai Jiangshan
2016-09-21 20:41:42 +08:00
parent 5c30a49c27
commit 1cf932a784
2 changed files with 15 additions and 5 deletions
+10
View File
@@ -3,6 +3,7 @@
#define APIVERSION 4242
// control command id
enum {
GETVERSION,
STARTPOD,
@@ -29,6 +30,15 @@ enum {
REMOVECONTAINER,
};
/*
* control message format
* | ctrl id | length | payload (length-8) |
* | . . . . | . . . . | . . . . . . . . . . . . |
* 0 4 8 length
*/
#define CONTROL_HEADER_SIZE 8
#define CONTROL_HEADER_LENGTH_OFFSET 4
/*
* stream message format
* | stream sequence | length | payload (length-12) |
+5 -5
View File
@@ -1179,15 +1179,15 @@ static int hyper_channel_handle(struct hyper_event *de, uint32_t len)
static int hyper_channel_read(struct hyper_event *he, int efd)
{
struct hyper_buf *buf = &he->rbuf;
uint32_t len = he->ops->len_offset + 4;
uint32_t len;
uint8_t data[4];
int size;
int ret;
fprintf(stdout, "%s\n", __func__);
if (buf->get < len) {
size = nonblock_read(he->fd, buf->data + buf->get, len - buf->get);
if (buf->get < CONTROL_HEADER_SIZE) {
size = nonblock_read(he->fd, buf->data + buf->get, CONTROL_HEADER_SIZE - buf->get);
if (size < 0) {
return size;
}
@@ -1197,12 +1197,12 @@ static int hyper_channel_read(struct hyper_event *he, int efd)
hyper_send_msg(he->fd, NEXT, 4, data);
}
buf->get += size;
if (buf->get < len) {
if (buf->get < CONTROL_HEADER_SIZE) {
return 0;
}
}
hyper_getmsg_len(he, &len);
len = hyper_get_be32(buf->data + CONTROL_HEADER_LENGTH_OFFSET);
fprintf(stdout, "get length %" PRIu32"\n", len);
// test it with '>=' to leave at least one byte in hyper_channel_handle(),
// so that hyper_channel_handle() can convert the data to c-string inplace.