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

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

Issue 269003002: Fix crash in raw_secure_server_socket_test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix status file. 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') | runtime/bin/socket_patch.dart » ('j') | 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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 void Handle::HandleIssueError() { 335 void Handle::HandleIssueError() {
336 DWORD error = GetLastError(); 336 DWORD error = GetLastError();
337 ASSERT(event_handler_ != NULL);
337 if (error == ERROR_BROKEN_PIPE) { 338 if (error == ERROR_BROKEN_PIPE) {
338 event_handler_->HandleClosed(this); 339 event_handler_->HandleClosed(this);
339 } else { 340 } else {
340 event_handler_->HandleError(this); 341 event_handler_->HandleError(this);
341 } 342 }
342 SetLastError(error); 343 SetLastError(error);
343 } 344 }
344 345
345 346
346 void FileHandle::EnsureInitialized(EventHandlerImplementation* event_handler) { 347 void FileHandle::EnsureInitialized(EventHandlerImplementation* event_handler) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 pending_read_ = buffer; 393 pending_read_ = buffer;
393 return true; 394 return true;
394 } 395 }
395 OverlappedBuffer::DisposeBuffer(buffer); 396 OverlappedBuffer::DisposeBuffer(buffer);
396 return false; 397 return false;
397 } 398 }
398 399
399 400
400 void SocketHandle::HandleIssueError() { 401 void SocketHandle::HandleIssueError() {
401 int error = WSAGetLastError(); 402 int error = WSAGetLastError();
403 ASSERT(event_handler_ != NULL);
402 if (error == WSAECONNRESET) { 404 if (error == WSAECONNRESET) {
403 event_handler_->HandleClosed(this); 405 event_handler_->HandleClosed(this);
404 } else { 406 } else {
405 event_handler_->HandleError(this); 407 event_handler_->HandleError(this);
406 } 408 }
407 WSASetLastError(error); 409 WSASetLastError(error);
408 } 410 }
409 411
410 412
411 bool ListenSocket::LoadAcceptEx() { 413 bool ListenSocket::LoadAcceptEx() {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 } else { 497 } else {
496 // Close the socket, as it's already accepted. 498 // Close the socket, as it's already accepted.
497 closesocket(buffer->client()); 499 closesocket(buffer->client());
498 } 500 }
499 501
500 pending_accept_count_--; 502 pending_accept_count_--;
501 OverlappedBuffer::DisposeBuffer(buffer); 503 OverlappedBuffer::DisposeBuffer(buffer);
502 } 504 }
503 505
504 506
507 static void DeleteIfClosed(Handle* handle) {
508 if (handle->IsClosed()) {
509 Dart_Port port = handle->port();
510 delete handle;
511 if (port != ILLEGAL_PORT) {
512 DartUtils::PostInt32(port, 1 << kDestroyedEvent);
513 }
514 }
515 }
516
517
505 void ListenSocket::DoClose() { 518 void ListenSocket::DoClose() {
506 closesocket(socket()); 519 closesocket(socket());
507 handle_ = INVALID_HANDLE_VALUE; 520 handle_ = INVALID_HANDLE_VALUE;
508 while (CanAccept()) { 521 while (CanAccept()) {
509 // Get rid of connections already accepted. 522 // Get rid of connections already accepted.
510 ClientSocket *client = Accept(); 523 ClientSocket *client = Accept();
511 if (client != NULL) { 524 if (client != NULL) {
512 client->Close(); 525 client->Close();
526 DeleteIfClosed(client);
513 } else { 527 } else {
514 break; 528 break;
515 } 529 }
516 } 530 }
517 } 531 }
518 532
519 533
520 bool ListenSocket::CanAccept() { 534 bool ListenSocket::CanAccept() {
521 ScopedLock lock(this); 535 ScopedLock lock(this);
522 return accepted_head_ != NULL; 536 return accepted_head_ != NULL;
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 962
949 963
950 void DatagramSocket::DoClose() { 964 void DatagramSocket::DoClose() {
951 // Just close the socket. This will cause any queued requests to be aborted. 965 // Just close the socket. This will cause any queued requests to be aborted.
952 closesocket(socket()); 966 closesocket(socket());
953 MarkClosedRead(); 967 MarkClosedRead();
954 MarkClosedWrite(); 968 MarkClosedWrite();
955 } 969 }
956 970
957 971
958 static void DeleteIfClosed(Handle* handle) {
959 if (handle->IsClosed()) {
960 Dart_Port port = handle->port();
961 delete handle;
962 if (port != ILLEGAL_PORT) {
963 DartUtils::PostInt32(port, 1 << kDestroyedEvent);
964 }
965 }
966 }
967
968
969 void EventHandlerImplementation::HandleInterrupt(InterruptMessage* msg) { 972 void EventHandlerImplementation::HandleInterrupt(InterruptMessage* msg) {
973 ASSERT(this != NULL);
970 if (msg->id == kTimeoutId) { 974 if (msg->id == kTimeoutId) {
971 // Change of timeout request. Just set the new timeout and port as the 975 // Change of timeout request. Just set the new timeout and port as the
972 // completion thread will use the new timeout value for its next wait. 976 // completion thread will use the new timeout value for its next wait.
973 timeout_queue_.UpdateTimeout(msg->dart_port, msg->data); 977 timeout_queue_.UpdateTimeout(msg->dart_port, msg->data);
974 } else if (msg->id == kShutdownId) { 978 } else if (msg->id == kShutdownId) {
975 shutdown_ = true; 979 shutdown_ = true;
976 } else { 980 } else {
977 // No tokens to return on Windows. 981 // No tokens to return on Windows.
978 if ((msg->data & (1 << kReturnTokenCommand)) != 0) return; 982 if ((msg->data & (1 << kReturnTokenCommand)) != 0) return;
979 Handle* handle = reinterpret_cast<Handle*>(msg->id); 983 Handle* handle = reinterpret_cast<Handle*>(msg->id);
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 OVERLAPPED* overlapped; 1286 OVERLAPPED* overlapped;
1283 int64_t millis = handler_impl->GetTimeout(); 1287 int64_t millis = handler_impl->GetTimeout();
1284 ASSERT(millis == kInfinityTimeout || millis >= 0); 1288 ASSERT(millis == kInfinityTimeout || millis >= 0);
1285 if (millis > kMaxInt32) millis = kMaxInt32; 1289 if (millis > kMaxInt32) millis = kMaxInt32;
1286 ASSERT(sizeof(int32_t) == sizeof(DWORD)); 1290 ASSERT(sizeof(int32_t) == sizeof(DWORD));
1287 BOOL ok = GetQueuedCompletionStatus(handler_impl->completion_port(), 1291 BOOL ok = GetQueuedCompletionStatus(handler_impl->completion_port(),
1288 &bytes, 1292 &bytes,
1289 &key, 1293 &key,
1290 &overlapped, 1294 &overlapped,
1291 static_cast<DWORD>(millis)); 1295 static_cast<DWORD>(millis));
1296
1292 if (!ok && overlapped == NULL) { 1297 if (!ok && overlapped == NULL) {
1293 if (GetLastError() == ERROR_ABANDONED_WAIT_0) { 1298 if (GetLastError() == ERROR_ABANDONED_WAIT_0) {
1294 // The completion port should never be closed. 1299 // The completion port should never be closed.
1295 Log::Print("Completion port closed\n"); 1300 Log::Print("Completion port closed\n");
1296 UNREACHABLE(); 1301 UNREACHABLE();
1297 } else { 1302 } else {
1298 // Timeout is signalled by false result and NULL in overlapped. 1303 // Timeout is signalled by false result and NULL in overlapped.
1299 handler_impl->HandleTimeout(); 1304 handler_impl->HandleTimeout();
1300 } 1305 }
1301 } else if (!ok) { 1306 } else if (!ok) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1343 1348
1344 1349
1345 void EventHandlerImplementation::Shutdown() { 1350 void EventHandlerImplementation::Shutdown() {
1346 SendData(kShutdownId, 0, 0); 1351 SendData(kShutdownId, 0, 0);
1347 } 1352 }
1348 1353
1349 } // namespace bin 1354 } // namespace bin
1350 } // namespace dart 1355 } // namespace dart
1351 1356
1352 #endif // defined(TARGET_OS_WINDOWS) 1357 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW
« no previous file with comments | « runtime/bin/eventhandler_win.h ('k') | runtime/bin/socket_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698