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

Side by Side Diff: runtime/bin/eventhandler_win.cc

Issue 265273002: Clean up windows eventhandler. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/eventhandler_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_WINDOWS) 6 #if defined(TARGET_OS_WINDOWS)
7 7
8 #include "bin/eventhandler.h" 8 #include "bin/eventhandler.h"
9 9
10 #include <winsock2.h> // NOLINT 10 #include <winsock2.h> // NOLINT
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 HandleIssueError(); 325 HandleIssueError();
326 return false; 326 return false;
327 } 327 }
328 328
329 329
330 bool Handle::IssueSendTo(struct sockaddr* sa, socklen_t sa_len) { 330 bool Handle::IssueSendTo(struct sockaddr* sa, socklen_t sa_len) {
331 return false; 331 return false;
332 } 332 }
333 333
334 334
335 static void HandleClosed(Handle* handle) {
336 if (!handle->IsClosing()) {
337 int event_mask = 1 << kCloseEvent;
338 DartUtils::PostInt32(handle->port(), event_mask);
339 }
340 }
341
342
343 static void HandleError(Handle* handle) {
344 handle->set_last_error(WSAGetLastError());
345 handle->MarkError();
346 if (!handle->IsClosing()) {
347 int event_mask = 1 << kErrorEvent;
348 DartUtils::PostInt32(handle->port(), event_mask);
349 }
350 }
351
352
335 void Handle::HandleIssueError() { 353 void Handle::HandleIssueError() {
336 DWORD error = GetLastError(); 354 DWORD error = GetLastError();
337 ASSERT(event_handler_ != NULL);
338 if (error == ERROR_BROKEN_PIPE) { 355 if (error == ERROR_BROKEN_PIPE) {
339 event_handler_->HandleClosed(this); 356 HandleClosed(this);
340 } else { 357 } else {
341 event_handler_->HandleError(this); 358 HandleError(this);
342 } 359 }
343 SetLastError(error); 360 SetLastError(error);
344 } 361 }
345 362
346 363
347 void FileHandle::EnsureInitialized(EventHandlerImplementation* event_handler) { 364 void FileHandle::EnsureInitialized(EventHandlerImplementation* event_handler) {
348 ScopedLock lock(this); 365 ScopedLock lock(this);
349 event_handler_ = event_handler; 366 event_handler_ = event_handler;
350 if (SupportsOverlappedIO() && completion_port_ == INVALID_HANDLE_VALUE) { 367 if (SupportsOverlappedIO() && completion_port_ == INVALID_HANDLE_VALUE) {
351 CreateCompletionPort(event_handler_->completion_port()); 368 CreateCompletionPort(event_handler_->completion_port());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 pending_read_ = buffer; 410 pending_read_ = buffer;
394 return true; 411 return true;
395 } 412 }
396 OverlappedBuffer::DisposeBuffer(buffer); 413 OverlappedBuffer::DisposeBuffer(buffer);
397 return false; 414 return false;
398 } 415 }
399 416
400 417
401 void SocketHandle::HandleIssueError() { 418 void SocketHandle::HandleIssueError() {
402 int error = WSAGetLastError(); 419 int error = WSAGetLastError();
403 ASSERT(event_handler_ != NULL);
404 if (error == WSAECONNRESET) { 420 if (error == WSAECONNRESET) {
405 event_handler_->HandleClosed(this); 421 HandleClosed(this);
406 } else { 422 } else {
407 event_handler_->HandleError(this); 423 HandleError(this);
408 } 424 }
409 WSASetLastError(error); 425 WSASetLastError(error);
410 } 426 }
411 427
412 428
413 bool ListenSocket::LoadAcceptEx() { 429 bool ListenSocket::LoadAcceptEx() {
414 // Load the AcceptEx function into memory using WSAIoctl. 430 // Load the AcceptEx function into memory using WSAIoctl.
415 GUID guid_accept_ex = WSAID_ACCEPTEX; 431 GUID guid_accept_ex = WSAID_ACCEPTEX;
416 DWORD bytes; 432 DWORD bytes;
417 int status = WSAIoctl(socket(), 433 int status = WSAIoctl(socket(),
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 ClientSocket* ListenSocket::Accept() { 556 ClientSocket* ListenSocket::Accept() {
541 ScopedLock lock(this); 557 ScopedLock lock(this);
542 if (accepted_head_ == NULL) return NULL; 558 if (accepted_head_ == NULL) return NULL;
543 ClientSocket* result = accepted_head_; 559 ClientSocket* result = accepted_head_;
544 accepted_head_ = accepted_head_->next(); 560 accepted_head_ = accepted_head_->next();
545 if (accepted_head_ == NULL) accepted_tail_ = NULL; 561 if (accepted_head_ == NULL) accepted_tail_ = NULL;
546 result->set_next(NULL); 562 result->set_next(NULL);
547 if (!IsClosing()) { 563 if (!IsClosing()) {
548 while (pending_accept_count() < 5) { 564 while (pending_accept_count() < 5) {
549 if (!IssueAccept()) { 565 if (!IssueAccept()) {
550 event_handler_->HandleError(this); 566 HandleError(this);
551 } 567 }
552 } 568 }
553 } 569 }
554 return result; 570 return result;
555 } 571 }
556 572
557 573
558 void ListenSocket::EnsureInitialized( 574 void ListenSocket::EnsureInitialized(
559 EventHandlerImplementation* event_handler) { 575 EventHandlerImplementation* event_handler) {
560 ScopedLock lock(this); 576 ScopedLock lock(this);
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 int event_mask = 1 << kInEvent; 1091 int event_mask = 1 << kInEvent;
1076 if ((listen_socket->mask() & event_mask) != 0) { 1092 if ((listen_socket->mask() & event_mask) != 0) {
1077 DartUtils::PostInt32(listen_socket->port(), event_mask); 1093 DartUtils::PostInt32(listen_socket->port(), event_mask);
1078 } 1094 }
1079 } 1095 }
1080 1096
1081 DeleteIfClosed(listen_socket); 1097 DeleteIfClosed(listen_socket);
1082 } 1098 }
1083 1099
1084 1100
1085 void EventHandlerImplementation::HandleClosed(Handle* handle) {
1086 if (!handle->IsClosing()) {
1087 int event_mask = 1 << kCloseEvent;
1088 DartUtils::PostInt32(handle->port(), event_mask);
1089 }
1090 }
1091
1092
1093 void EventHandlerImplementation::HandleError(Handle* handle) {
1094 handle->set_last_error(WSAGetLastError());
1095 handle->MarkError();
1096 if (!handle->IsClosing()) {
1097 int event_mask = 1 << kErrorEvent;
1098 DartUtils::PostInt32(handle->port(), event_mask);
1099 }
1100 }
1101
1102
1103 void EventHandlerImplementation::HandleRead(Handle* handle, 1101 void EventHandlerImplementation::HandleRead(Handle* handle,
1104 int bytes, 1102 int bytes,
1105 OverlappedBuffer* buffer) { 1103 OverlappedBuffer* buffer) {
1106 buffer->set_data_length(bytes); 1104 buffer->set_data_length(bytes);
1107 handle->ReadComplete(buffer); 1105 handle->ReadComplete(buffer);
1108 if (bytes > 0) { 1106 if (bytes > 0) {
1109 if (!handle->IsClosing()) { 1107 if (!handle->IsClosing()) {
1110 int event_mask = 1 << kInEvent; 1108 int event_mask = 1 << kInEvent;
1111 if ((handle->mask() & event_mask) != 0) { 1109 if ((handle->mask() & event_mask) != 0) {
1112 DartUtils::PostInt32(handle->port(), event_mask); 1110 DartUtils::PostInt32(handle->port(), event_mask);
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1348 1346
1349 1347
1350 void EventHandlerImplementation::Shutdown() { 1348 void EventHandlerImplementation::Shutdown() {
1351 SendData(kShutdownId, 0, 0); 1349 SendData(kShutdownId, 0, 0);
1352 } 1350 }
1353 1351
1354 } // namespace bin 1352 } // namespace bin
1355 } // namespace dart 1353 } // namespace dart
1356 1354
1357 #endif // defined(TARGET_OS_WINDOWS) 1355 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW
« no previous file with comments | « runtime/bin/eventhandler_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698