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/builtin.h" | 8 #include "bin/builtin.h" |
9 #include "bin/eventhandler.h" | 9 #include "bin/eventhandler.h" |
10 #include "bin/file.h" | 10 #include "bin/file.h" |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 closesocket(s); | 518 closesocket(s); |
519 delete listen_socket; | 519 delete listen_socket; |
520 SetLastError(rc); | 520 SetLastError(rc); |
521 return -1; | 521 return -1; |
522 } | 522 } |
523 | 523 |
524 return reinterpret_cast<intptr_t>(listen_socket); | 524 return reinterpret_cast<intptr_t>(listen_socket); |
525 } | 525 } |
526 | 526 |
527 | 527 |
| 528 bool ServerSocket::StartAccept(intptr_t fd) { |
| 529 ListenSocket* listen_socket = reinterpret_cast<ListenSocket*>(fd); |
| 530 listen_socket->EnsureInitialized(EventHandler::delegate()); |
| 531 // Always keep 5 outstanding accepts going, to enhance performance. |
| 532 for (int i = 0; i < 5; i++) { |
| 533 if (!listen_socket->IssueAccept()) { |
| 534 DWORD rc = WSAGetLastError(); |
| 535 listen_socket->Close(); |
| 536 if (!listen_socket->HasPendingAccept()) { |
| 537 // Delete socket now, if there are no pending accepts. Otherwise, |
| 538 // the event-handler will take care of deleting it. |
| 539 delete listen_socket; |
| 540 } |
| 541 SetLastError(rc); |
| 542 return false; |
| 543 } |
| 544 } |
| 545 return true; |
| 546 } |
| 547 |
| 548 |
528 void Socket::Close(intptr_t fd) { | 549 void Socket::Close(intptr_t fd) { |
529 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(fd); | 550 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(fd); |
530 client_socket->Close(); | 551 client_socket->Close(); |
531 } | 552 } |
532 | 553 |
533 | 554 |
534 static bool SetBlockingHelper(intptr_t fd, bool blocking) { | 555 static bool SetBlockingHelper(intptr_t fd, bool blocking) { |
535 SocketHandle* handle = reinterpret_cast<SocketHandle*>(fd); | 556 SocketHandle* handle = reinterpret_cast<SocketHandle*>(fd); |
536 u_long iMode = blocking ? 0 : 1; | 557 u_long iMode = blocking ? 0 : 1; |
537 int status = ioctlsocket(handle->socket(), FIONBIO, &iMode); | 558 int status = ioctlsocket(handle->socket(), FIONBIO, &iMode); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 proto, | 721 proto, |
701 MCAST_LEAVE_GROUP, | 722 MCAST_LEAVE_GROUP, |
702 reinterpret_cast<char *>(&mreq), | 723 reinterpret_cast<char *>(&mreq), |
703 sizeof(mreq)) == 0; | 724 sizeof(mreq)) == 0; |
704 } | 725 } |
705 | 726 |
706 } // namespace bin | 727 } // namespace bin |
707 } // namespace dart | 728 } // namespace dart |
708 | 729 |
709 #endif // defined(TARGET_OS_WINDOWS) | 730 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |