Merge pull request #222 from laijs/event-hanghup

change policy for event hangup
This commit is contained in:
Gao feng
2016-10-19 13:13:33 +08:00
committed by GitHub
2 changed files with 12 additions and 22 deletions

View File

@@ -157,32 +157,23 @@ int hyper_handle_event(int efd, struct epoll_event *event)
fprintf(stdout, "%s get event %d, he %p, fd %d. ops %p\n",
__func__, event->events, he, he->fd, he->ops);
/* do not handle hup event if have in event */
/* do not handle hup event if have in/out event */
if ((event->events & EPOLLIN) && he->ops->read) {
fprintf(stdout, "%s event EPOLLIN, he %p, fd %d, %p\n",
__func__, he, he->fd, he->ops);
if (he->ops->read && he->ops->read(he, efd) < 0)
return -1;
} else if (event->events & EPOLLHUP) {
fprintf(stdout, "%s event EPOLLHUP, he %p, fd %d, %p\n",
__func__, he, he->fd, he->ops);
if (he->ops->hup)
he->ops->hup(he, efd);
return 0;
return he->ops->read(he, efd);
}
if (event->events & EPOLLOUT) {
if ((event->events & EPOLLOUT) && he->ops->write) {
fprintf(stdout, "%s event EPOLLOUT, he %p, fd %d, %p\n",
__func__, he, he->fd, he->ops);
if (he->ops->write && he->ops->write(he, efd) < 0)
return -1;
return he->ops->write(he, efd);
}
if (event->events & EPOLLERR) {
fprintf(stdout, "get epoll err on event: %p\n", he);
if ((event->events & EPOLLHUP) || (event->events & EPOLLERR)) {
fprintf(stdout, "%s event EPOLLHUP or EPOLLERR, he %p, fd %d, %x\n",
__func__, he, he->fd, event->events);
if (he->ops->hup)
he->ops->hup(he, efd);
return 0;
}
return 0;

View File

@@ -115,8 +115,9 @@ static int pts_loop(struct hyper_event *de, uint64_t seq, int efd, struct hyper_
continue;
if (errno != EAGAIN && errno != EIO) {
perror("fail to read tty fd");
return -1;
perror("failed to read process's stdout/stderr");
pts_hup(de, efd, exec);
return 0;
}
break;
@@ -152,12 +153,10 @@ static int write_to_stdin(struct hyper_event *de, int efd)
struct hyper_exec *exec = container_of(de, struct hyper_exec, stdinev);
fprintf(stdout, "%s, seq %" PRIu64"\n", __func__, exec->seq);
int ret = hyper_event_write(de, efd);
if (ret >= 0 && de->wbuf.get == 0 && exec->close_stdin_request)
if (hyper_event_write(de, efd) < 0 || (de->wbuf.get == 0 && exec->close_stdin_request))
pts_hup(de, efd, exec);
return ret;
return 0;
}
struct hyper_event_ops in_ops = {