handle eof for the stdio handling

Signed-off-by: Lai Jiangshan <jiangshanlai@gmail.com>
This commit is contained in:
Lai Jiangshan
2016-03-08 21:02:42 +08:00
parent 013cbb7e1a
commit 3fa27e7464
3 changed files with 14 additions and 10 deletions
+2 -2
View File
@@ -107,7 +107,7 @@ static int hyper_getmsg_len(struct hyper_event *de, uint32_t *len)
return 0;
}
int hyper_event_read(struct hyper_event *de)
int hyper_event_read(struct hyper_event *de, int efd)
{
struct hyper_buf *buf = &de->rbuf;
uint32_t len = 4;
@@ -233,7 +233,7 @@ int hyper_handle_event(int efd, struct epoll_event *event)
if (event->events & EPOLLIN) {
fprintf(stdout, "%s event EPOLLIN, de %p, fd %d, %p\n",
__func__, de, de->fd, de->ops);
if (de->ops->read(de) < 0)
if (de->ops->read(de, efd) < 0)
return -1;
} else if (event->events & EPOLLHUP) {
fprintf(stdout, "%s event EPOLLHUP, de %p, fd %d, %p\n",
+2 -2
View File
@@ -7,7 +7,7 @@
struct hyper_event;
struct hyper_event_ops {
int (*read)(struct hyper_event *e);
int (*read)(struct hyper_event *e, int efd);
int (*write)(struct hyper_event *e);
int (*handle)(struct hyper_event *e, uint32_t len);
void (*hup)(struct hyper_event *e, int efd);
@@ -39,6 +39,6 @@ int hyper_init_event(struct hyper_event *de, struct hyper_event_ops *ops,
int hyper_handle_event(int efd, struct epoll_event *event);
void hyper_reset_event(struct hyper_event *de);
void hyper_event_hup(struct hyper_event *de, int efd);
int hyper_event_read(struct hyper_event *de);
int hyper_event_read(struct hyper_event *dei, int efd);
int hyper_event_write(struct hyper_event *de);
#endif
+10 -6
View File
@@ -101,7 +101,7 @@ static void stderr_hup(struct hyper_event *de, int efd)
return pts_hup(de, efd, 0);
}
static int pts_loop(struct hyper_event *de, uint64_t seq)
static int pts_loop(struct hyper_event *de, uint64_t seq, int efd, int out)
{
int size = -1;
struct hyper_buf *buf = &ctl.tty.wbuf;
@@ -109,7 +109,7 @@ static int pts_loop(struct hyper_event *de, uint64_t seq)
while ((buf->get + 12 < buf->size) && size) {
size = read(de->fd, buf->data + buf->get + 12, buf->size - buf->get - 12);
fprintf(stdout, "%s: read %d data\n", __func__, size);
if (size <= 0) {
if (size < 0) {
if (errno == EINTR)
continue;
@@ -120,6 +120,10 @@ static int pts_loop(struct hyper_event *de, uint64_t seq)
break;
}
if (size == 0) { // eof
pts_hup(de, efd, out);
break;
}
hyper_set_be64(buf->data + buf->get, seq);
hyper_set_be32(buf->data + buf->get + 8, size + 12);
@@ -134,12 +138,12 @@ static int pts_loop(struct hyper_event *de, uint64_t seq)
return 0;
}
static int stdout_loop(struct hyper_event *de)
static int stdout_loop(struct hyper_event *de, int efd)
{
struct hyper_exec *exec = container_of(de, struct hyper_exec, e);
fprintf(stdout, "%s, seq %" PRIu64"\n", __func__, exec->seq);
return pts_loop(de, exec->seq);
return pts_loop(de, exec->seq, efd, 1);
}
struct hyper_event_ops pts_ops = {
@@ -150,12 +154,12 @@ struct hyper_event_ops pts_ops = {
/* don't need read buff, the pts data will store in tty buffer */
};
static int stderr_loop(struct hyper_event *de)
static int stderr_loop(struct hyper_event *de, int efd)
{
struct hyper_exec *exec = container_of(de, struct hyper_exec, errev);
fprintf(stdout, "%s, seq %" PRIu64"\n", __func__, exec->errseq);
return pts_loop(de, exec->errseq);
return pts_loop(de, exec->errseq, efd, 0);
}
struct hyper_event_ops err_ops = {