diff --git a/src/exec.c b/src/exec.c index 1fa18ec..b5cff2e 100644 --- a/src/exec.c +++ b/src/exec.c @@ -551,8 +551,7 @@ int hyper_release_exec(struct hyper_exec *exec, if (pod->type == STOPPOD) { /* stop pod manually */ - hyper_send_type(ctl.chan.fd, ACK); - + hyper_send_msg_block(ctl.chan.fd, ACK, 0, NULL); } else { /* send out pod finish message, hyper will decide if restart pod or not */ hyper_send_pod_finished(pod); diff --git a/src/init.c b/src/init.c index 8925278..d12f0bf 100644 --- a/src/init.c +++ b/src/init.c @@ -516,7 +516,7 @@ static int hyper_setup_container(struct hyper_pod *pod) fprintf(stdout, "pod init pid %d\n", pod->init_pid); /* Wait for container start */ - if (hyper_get_type_block(arg.ctl_pipe[0], &type) < 0) { + if (hyper_get_type(arg.ctl_pipe[0], &type) < 0) { perror("get container init ready message failed"); goto out; } @@ -1183,9 +1183,9 @@ static int hyper_channel_handle(struct hyper_event *de, uint32_t len) } if (ret < 0) - hyper_send_type(de->fd, ERROR); + hyper_send_msg_block(de->fd, ERROR, 0, NULL); else - hyper_send_msg(de->fd, ACK, datalen, data); + hyper_send_msg_block(de->fd, ACK, datalen, data); free(data); return 0; diff --git a/src/net.c b/src/net.c index 865af9f..b4810c1 100644 --- a/src/net.c +++ b/src/net.c @@ -112,9 +112,9 @@ int hyper_get_type(int fd, uint32_t *type) return 0; } -int hyper_get_type_block(int fd, uint32_t *type) +int hyper_send_msg_block(int fd, uint32_t type, uint32_t len, uint8_t *data) { - int ret = 0, flags; + int ret, flags; flags = hyper_setfd_block(fd); if (flags < 0) { @@ -122,10 +122,7 @@ int hyper_get_type_block(int fd, uint32_t *type) return -1; } - ret = hyper_get_type(fd, type); - if (ret < 0) { - fprintf(stderr, "%s can not get type\n", __func__); - } + ret = hyper_send_msg(fd, type, len, data); if (fcntl(fd, F_SETFL, flags) < 0) { perror("restore fd flag failed"); @@ -135,43 +132,6 @@ int hyper_get_type_block(int fd, uint32_t *type) return ret; } -int hyper_send_type_block(int fd, uint32_t type, int need_ack) -{ - int ret = 0, flags; - uint32_t t; - - flags = hyper_setfd_block(fd); - if (flags < 0) { - fprintf(stderr, "%s fail to set fd block\n", __func__); - return -1; - } - - ret = hyper_send_msg(fd, type, 0, NULL); - if (ret < 0) - goto out; - - if (need_ack == 0) - goto out; - - ret = hyper_get_type(fd, &t); - if (ret < 0) { - fprintf(stderr, "can not get type\n"); - goto out; - } - - fprintf(stdout, "get type %" PRIu32"\n", type); - - if (t != ACK) - ret = -1; -out: - if (fcntl(fd, F_SETFL, flags) < 0) { - perror("restore fd flag failed"); - return -1; - } - - return ret; -} - static int get_addr_ipv4(uint8_t *ap, const char *cp) { int i; diff --git a/src/net.h b/src/net.h index e096f21..c16fb8b 100644 --- a/src/net.h +++ b/src/net.h @@ -51,10 +51,9 @@ void hyper_cleanup_network(struct hyper_pod *pod); int hyper_setup_dns(struct hyper_pod *pod); void hyper_cleanup_dns(struct hyper_pod *pod); int hyper_get_type(int fd, uint32_t *type); -int hyper_get_type_block(int fd, uint32_t *type); int hyper_send_type(int fd, uint32_t type); int hyper_send_type_block(int fd, uint32_t type, int need_ack); -int hyper_send_msg(int fd, uint32_t type, uint32_t len, - uint8_t *message); +int hyper_send_msg(int fd, uint32_t type, uint32_t len, uint8_t *data); +int hyper_send_msg_block(int fd, uint32_t type, uint32_t len, uint8_t *data); int hyper_send_data(int fd, uint8_t *data, uint32_t len); #endif diff --git a/src/util.c b/src/util.c index 225375e..ea2f1a8 100644 --- a/src/util.c +++ b/src/util.c @@ -401,7 +401,7 @@ int hyper_send_pod_finished(struct hyper_pod *pod) data = new; } - ret = hyper_send_msg(ctl.chan.fd, PODFINISHED, c_num * 4, data); + ret = hyper_send_msg_block(ctl.chan.fd, PODFINISHED, c_num * 4, data); out: free(data); return ret;