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

Unified Diff: runtime/bin/eventhandler_win.cc

Issue 11606020: Reapply "Fixes to eventhandler and HTTP"" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove invalid assert (fixes Windows test) Created 8 years 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
« no previous file with comments | « runtime/bin/eventhandler_win.h ('k') | runtime/bin/socket.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/eventhandler_win.cc
diff --git a/runtime/bin/eventhandler_win.cc b/runtime/bin/eventhandler_win.cc
index bc2f48022ede17291f4331313c8cad343c9915f4..b30514f92d8f94b911165bfa85b54d12660666a0 100644
--- a/runtime/bin/eventhandler_win.cc
+++ b/runtime/bin/eventhandler_win.cc
@@ -258,12 +258,13 @@ bool Handle::IssueRead() {
pending_read_ = buffer;
return true;
}
+ IOBuffer::DisposeBuffer(buffer);
- if (GetLastError() != ERROR_BROKEN_PIPE) {
- Log::PrintErr("ReadFile failed: %d\n", GetLastError());
+ if (GetLastError() == ERROR_BROKEN_PIPE) {
+ event_handler_->HandleClosed(this);
+ } else {
+ event_handler_->HandleError(this);
}
- event_handler_->HandleClosed(this);
- IOBuffer::DisposeBuffer(buffer);
return false;
} else {
// Completing asynchronously through thread.
@@ -297,12 +298,13 @@ bool Handle::IssueWrite() {
pending_write_ = buffer;
return true;
}
+ IOBuffer::DisposeBuffer(buffer);
- if (GetLastError() != ERROR_BROKEN_PIPE) {
- Log::PrintErr("WriteFile failed: %d\n", GetLastError());
+ if (GetLastError() == ERROR_BROKEN_PIPE) {
+ event_handler_->HandleClosed(this);
+ } else {
+ event_handler_->HandleError(this);
}
- event_handler_->HandleClosed(this);
- IOBuffer::DisposeBuffer(buffer);
return false;
}
@@ -558,12 +560,14 @@ bool ClientSocket::IssueRead() {
pending_read_ = buffer;
return true;
}
+ IOBuffer::DisposeBuffer(buffer);
+ pending_read_ = NULL;
- if (WSAGetLastError() != WSAECONNRESET) {
- Log::PrintErr("WSARecv failed: %d\n", WSAGetLastError());
+ if (WSAGetLastError() == WSAECONNRESET) {
+ event_handler_->HandleClosed(this);
+ } else {
+ event_handler_->HandleError(this);
}
- event_handler_->HandleClosed(this);
- IOBuffer::DisposeBuffer(buffer);
return false;
}
@@ -584,10 +588,14 @@ bool ClientSocket::IssueWrite() {
if (rc == NO_ERROR || WSAGetLastError() == WSA_IO_PENDING) {
return true;
}
-
- Log::PrintErr("WSASend failed: %d\n", WSAGetLastError());
IOBuffer::DisposeBuffer(pending_write_);
pending_write_ = NULL;
+
+ if (WSAGetLastError() == WSAECONNRESET) {
+ event_handler_->HandleClosed(this);
+ } else {
+ event_handler_->HandleError(this);
+ }
return false;
}
@@ -657,36 +665,41 @@ void EventHandlerImplementation::HandleInterrupt(InterruptMessage* msg) {
Handle::ScopedLock lock(handle);
- // If the data available callback has been requested and data are
- // available post it immediately. Otherwise make sure that a pending
- // read is issued unless the socket is already closed for read.
- if ((msg->data & (1 << kInEvent)) != 0) {
- if (handle->Available() > 0) {
- int event_mask = (1 << kInEvent);
- DartUtils::PostInt32(handle->port(), event_mask);
- } else if (!handle->HasPendingRead() &&
- !handle->IsClosedRead()) {
- handle->IssueRead();
+ if (!handle->IsError()) {
+ // If in events (data available events) have been requested, and data
+ // is available, post an in event immediately. Otherwise make sure
+ // that a pending read is issued, unless the socket is already closed
+ // for read.
+ if ((msg->data & (1 << kInEvent)) != 0) {
+ if (handle->Available() > 0) {
+ int event_mask = (1 << kInEvent);
+ handle->set_mask(handle->mask() & ~event_mask);
+ DartUtils::PostInt32(handle->port(), event_mask);
+ } else if (!handle->HasPendingRead() &&
+ !handle->IsClosedRead()) {
+ handle->IssueRead();
+ }
}
- }
- // If can send callback had been requested and there is no pending
- // send post it immediately.
- if ((msg->data & (1 << kOutEvent)) != 0) {
- if (!handle->HasPendingWrite()) {
- int event_mask = (1 << kOutEvent);
- DartUtils::PostInt32(handle->port(), event_mask);
+ // If out events (can write events) have been requested, and there
+ // are no pending writes, post an out event immediately.
+ if ((msg->data & (1 << kOutEvent)) != 0) {
+ if (!handle->HasPendingWrite()) {
+ int event_mask = (1 << kOutEvent);
+ handle->set_mask(handle->mask() & ~event_mask);
+ DartUtils::PostInt32(handle->port(), event_mask);
+ }
}
- }
- if (handle->is_client_socket()) {
- ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(handle);
- if ((msg->data & (1 << kShutdownReadCommand)) != 0) {
- client_socket->Shutdown(SD_RECEIVE);
- }
+ if (handle->is_client_socket()) {
+ ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(handle);
+ if ((msg->data & (1 << kShutdownReadCommand)) != 0) {
+ client_socket->Shutdown(SD_RECEIVE);
+ }
- if ((msg->data & (1 << kShutdownWriteCommand)) != 0) {
- client_socket->Shutdown(SD_SEND);
+ if ((msg->data & (1 << kShutdownWriteCommand)) != 0) {
+ client_socket->Shutdown(SD_SEND);
+ }
}
}
@@ -731,6 +744,7 @@ void EventHandlerImplementation::HandleClosed(Handle* handle) {
void EventHandlerImplementation::HandleError(Handle* handle) {
handle->set_last_error(WSAGetLastError());
+ handle->MarkError();
if (!handle->IsClosing()) {
int event_mask = 1 << kErrorEvent;
DartUtils::PostInt32(handle->port(), event_mask);
@@ -771,7 +785,7 @@ void EventHandlerImplementation::HandleWrite(Handle* handle,
handle->WriteComplete(buffer);
if (bytes > 0) {
- if (!handle->IsClosing()) {
+ if (!handle->IsError() && !handle->IsClosing()) {
int event_mask = 1 << kOutEvent;
if ((handle->mask() & event_mask) != 0) {
DartUtils::PostInt32(handle->port(), event_mask);
« no previous file with comments | « runtime/bin/eventhandler_win.h ('k') | runtime/bin/socket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698