Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 if (status == SOCKET_ERROR) { | 422 if (status == SOCKET_ERROR) { |
| 423 Log::PrintErr("Error WSAIoctl failed: %d\n", WSAGetLastError()); | 423 Log::PrintErr("Error WSAIoctl failed: %d\n", WSAGetLastError()); |
| 424 return false; | 424 return false; |
| 425 } | 425 } |
| 426 return true; | 426 return true; |
| 427 } | 427 } |
| 428 | 428 |
| 429 | 429 |
| 430 bool ListenSocket::IssueAccept() { | 430 bool ListenSocket::IssueAccept() { |
| 431 ScopedLock lock(this); | 431 ScopedLock lock(this); |
| 432 | |
| 433 // For AcceptEx there needs to be buffer storage for address | 432 // For AcceptEx there needs to be buffer storage for address |
| 434 // information for two addresses (local and remote address). The | 433 // information for two addresses (local and remote address). The |
| 435 // AcceptEx documentation says: "This value must be at least 16 | 434 // AcceptEx documentation says: "This value must be at least 16 |
| 436 // bytes more than the maximum address length for the transport | 435 // bytes more than the maximum address length for the transport |
| 437 // protocol in use." | 436 // protocol in use." |
| 438 static const int kAcceptExAddressAdditionalBytes = 16; | 437 static const int kAcceptExAddressAdditionalBytes = 16; |
| 439 static const int kAcceptExAddressStorageSize = | 438 static const int kAcceptExAddressStorageSize = |
| 440 sizeof(SOCKADDR_STORAGE) + kAcceptExAddressAdditionalBytes; | 439 sizeof(SOCKADDR_STORAGE) + kAcceptExAddressAdditionalBytes; |
| 441 OverlappedBuffer* buffer = | 440 OverlappedBuffer* buffer = |
| 442 OverlappedBuffer::AllocateAcceptBuffer(2 * kAcceptExAddressStorageSize); | 441 OverlappedBuffer::AllocateAcceptBuffer(2 * kAcceptExAddressStorageSize); |
| 443 DWORD received; | 442 DWORD received; |
| 444 BOOL ok; | 443 BOOL ok; |
| 445 ok = AcceptEx_(socket(), | 444 ok = AcceptEx_(socket(), |
| 446 buffer->client(), | 445 buffer->client(), |
| 447 buffer->GetBufferStart(), | 446 buffer->GetBufferStart(), |
| 448 0, // For now don't receive data with accept. | 447 0, // For now don't receive data with accept. |
| 449 kAcceptExAddressStorageSize, | 448 kAcceptExAddressStorageSize, |
| 450 kAcceptExAddressStorageSize, | 449 kAcceptExAddressStorageSize, |
| 451 &received, | 450 &received, |
| 452 buffer->GetCleanOverlapped()); | 451 buffer->GetCleanOverlapped()); |
| 453 if (!ok) { | 452 if (!ok) { |
| 454 if (WSAGetLastError() != WSA_IO_PENDING) { | 453 if (WSAGetLastError() != WSA_IO_PENDING) { |
| 455 Log::PrintErr("AcceptEx failed: %d\n", WSAGetLastError()); | 454 int error = WSAGetLastError(); |
| 456 closesocket(buffer->client()); | 455 closesocket(buffer->client()); |
| 457 OverlappedBuffer::DisposeBuffer(buffer); | 456 OverlappedBuffer::DisposeBuffer(buffer); |
| 457 WSASetLastError(error); | |
| 458 return false; | 458 return false; |
| 459 } | 459 } |
| 460 } | 460 } |
| 461 | 461 |
| 462 pending_accept_count_++; | 462 pending_accept_count_++; |
| 463 | 463 |
| 464 return true; | 464 return true; |
| 465 } | 465 } |
| 466 | 466 |
| 467 | 467 |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 964 | 964 |
| 965 // If incoming connections are requested make sure to post already | 965 // If incoming connections are requested make sure to post already |
| 966 // accepted connections. | 966 // accepted connections. |
| 967 if ((msg->data & (1 << kInEvent)) != 0) { | 967 if ((msg->data & (1 << kInEvent)) != 0) { |
| 968 if (listen_socket->CanAccept()) { | 968 if (listen_socket->CanAccept()) { |
| 969 int event_mask = (1 << kInEvent); | 969 int event_mask = (1 << kInEvent); |
| 970 handle->set_mask(handle->mask() & ~event_mask); | 970 handle->set_mask(handle->mask() & ~event_mask); |
| 971 DartUtils::PostInt32(handle->port(), event_mask); | 971 DartUtils::PostInt32(handle->port(), event_mask); |
| 972 } | 972 } |
| 973 // Always keep 5 outstanding accepts going, to enhance performance. | 973 // Always keep 5 outstanding accepts going, to enhance performance. |
| 974 while (listen_socket->pending_accept_count() < 5) { | 974 bool accept_success = true; |
| 975 listen_socket->IssueAccept(); | 975 while (listen_socket->pending_accept_count() < 5 && accept_success) { |
| 976 accept_success = listen_socket->IssueAccept(); | |
| 977 if (!accept_success) { | |
|
Anders Johnsen
2013/12/18 16:24:33
Move issue-accept into if and remove the boolean,
Søren Gjesse
2014/01/02 08:37:33
Done.
| |
| 978 HandleError(listen_socket); | |
| 979 } | |
| 976 } | 980 } |
| 977 } | 981 } |
| 978 | 982 |
| 979 if ((msg->data & (1 << kCloseCommand)) != 0) { | 983 if ((msg->data & (1 << kCloseCommand)) != 0) { |
| 980 listen_socket->Close(); | 984 listen_socket->Close(); |
| 981 } | 985 } |
| 982 } else { | 986 } else { |
| 983 handle->EnsureInitialized(this); | 987 handle->EnsureInitialized(this); |
| 984 | 988 |
| 985 Handle::ScopedLock lock(handle); | 989 Handle::ScopedLock lock(handle); |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1303 | 1307 |
| 1304 | 1308 |
| 1305 void EventHandlerImplementation::Shutdown() { | 1309 void EventHandlerImplementation::Shutdown() { |
| 1306 SendData(kShutdownId, 0, 0); | 1310 SendData(kShutdownId, 0, 0); |
| 1307 } | 1311 } |
| 1308 | 1312 |
| 1309 } // namespace bin | 1313 } // namespace bin |
| 1310 } // namespace dart | 1314 } // namespace dart |
| 1311 | 1315 |
| 1312 #endif // defined(TARGET_OS_WINDOWS) | 1316 #endif // defined(TARGET_OS_WINDOWS) |
| OLD | NEW |