introduce hyper_send_msg_block

the control serial port is opened as unblock fd, set
is as block fd to make sure sending successfully.

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
This commit is contained in:
Gao feng
2015-12-10 11:07:07 +08:00
parent f49d1247d2
commit 2b1edeceb4
5 changed files with 10 additions and 52 deletions
+1 -2
View File
@@ -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);
+3 -3
View File
@@ -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;
+3 -43
View File
@@ -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;
+2 -3
View File
@@ -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
+1 -1
View File
@@ -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;