enable using api command data as c-string inplace

Signed-off-by: Lai Jiangshan <jiangshanlai@gmail.com>
This commit is contained in:
Lai Jiangshan
2016-09-14 10:40:03 +08:00
parent 70dd9f1447
commit e2b79425f1
2 changed files with 5 additions and 1 deletions
+3 -1
View File
@@ -165,7 +165,9 @@ int hyper_event_read(struct hyper_event *he, int efd)
}
fprintf(stdout, "get length %" PRIu32"\n", len);
if (len > buf->size) {
// test it with '>=' to leave at least one byte in handle(),
// so that handle() can convert the data to c-string inplace.
if (len >= buf->size) {
fprintf(stderr, "get length %" PRIu32", too long\n", len);
return -1;
}
+2
View File
@@ -1054,6 +1054,8 @@ static int hyper_channel_handle(struct hyper_event *de, uint32_t len)
uint8_t *data = NULL;
int i, ret = 0;
// append a null byte to it. hyper_event_read() left this room for us.
buf->data[buf->get] = 0;
for (i = 0; i < buf->get; i++)
fprintf(stdout, "%0x ", buf->data[i]);