Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Unified Diff: runtime/bin/eventhandler_linux.cc

Issue 8533005: Better handling of stdin/stdout/stderr (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Minor fix Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/bin/eventhandler_linux.cc
diff --git a/runtime/bin/eventhandler_linux.cc b/runtime/bin/eventhandler_linux.cc
index 9764ac28484892ff52b602c15f273648b9152df3..b0e29507c82bca2ac65d973c6b81aa2e24c50179 100644
--- a/runtime/bin/eventhandler_linux.cc
+++ b/runtime/bin/eventhandler_linux.cc
@@ -243,25 +243,36 @@ intptr_t EventHandlerImplementation::GetPollEvents(struct pollfd* pollfd) {
} else if ((pollfd->revents & POLLERR) != 0) {
event_mask = (1 << kErrorEvent);
} else {
- // If POLLIN is set with no available data and no POLLHUP use
- // recv to peek for whether the other end of the socket
- // actually closed.
- char buffer;
- ssize_t bytesPeeked = recv(sd->fd(), &buffer, 1, MSG_PEEK);
- if (bytesPeeked == 0) {
- event_mask = (1 << kCloseEvent);
- sd->MarkClosedRead();
- } else if (errno != EAGAIN) {
- fprintf(stderr, "Error recv: %s\n", strerror(errno));
+ if (sd->IsPipe()) {
+ // For stdin when reading from a terminal treat POLLIN with 0
+ // available bytes as end-of-file.
+ if (sd->fd() == STDIN_FILENO && isatty(sd->fd())) {
+ event_mask = (1 << kCloseEvent);
+ sd->MarkClosedRead();
+ }
+ } else {
+ // If POLLIN is set with no available data and no POLLHUP use
+ // recv to peek for whether the other end of the socket
+ // actually closed.
+ char buffer;
+ ssize_t bytesPeeked = recv(sd->fd(), &buffer, 1, MSG_PEEK);
+ if (bytesPeeked == 0) {
+ event_mask = (1 << kCloseEvent);
+ sd->MarkClosedRead();
+ } else if (errno != EAGAIN) {
+ fprintf(stderr, "Error recv: %s\n", strerror(errno));
+ }
}
}
}
// On pipes POLLHUP is reported without POLLIN.
- if (((pollfd->revents & POLLIN) == 0) &&
- ((pollfd->revents & POLLHUP) != 0)) {
- event_mask = (1 << kCloseEvent);
- sd->MarkClosedRead();
+ if (sd->IsPipe()) {
+ if (((pollfd->revents & POLLIN) == 0) &&
+ ((pollfd->revents & POLLHUP) != 0)) {
+ event_mask = (1 << kCloseEvent);
+ sd->MarkClosedRead();
+ }
}
if ((pollfd->revents & POLLOUT) != 0) event_mask |= (1 << kOutEvent);

Powered by Google App Engine
This is Rietveld 408576698