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 15 matching lines...) Expand all Loading... | |
| 26 | 26 |
| 27 static const int kBufferSize = 64 * 1024; | 27 static const int kBufferSize = 64 * 1024; |
| 28 static const int kStdOverlappedBufferSize = 16 * 1024; | 28 static const int kStdOverlappedBufferSize = 16 * 1024; |
| 29 | 29 |
| 30 static const int kInfinityTimeout = -1; | 30 static const int kInfinityTimeout = -1; |
| 31 static const int kTimeoutId = -1; | 31 static const int kTimeoutId = -1; |
| 32 static const int kShutdownId = -2; | 32 static const int kShutdownId = -2; |
| 33 | 33 |
| 34 OverlappedBuffer* OverlappedBuffer::AllocateBuffer(int buffer_size, | 34 OverlappedBuffer* OverlappedBuffer::AllocateBuffer(int buffer_size, |
| 35 Operation operation) { | 35 Operation operation) { |
| 36 int actual_size = buffer_size; | |
| 37 // For calling recvfrom additional buffer space is needed for the source | |
| 38 // address information. | |
| 39 if (operation == kRecvFrom) { | |
|
Anders Johnsen
2013/12/12 12:19:58
Move this to AllocateRecvFromBuffer?
Søren Gjesse
2013/12/12 15:44:39
Done.
| |
| 40 actual_size += sizeof(socklen_t) + sizeof(struct sockaddr_storage); | |
|
Anders Johnsen
2013/12/12 12:19:58
Make the size a constant in OverlappedBuffer.
Søren Gjesse
2013/12/12 15:44:39
Done.
| |
| 41 } | |
| 36 OverlappedBuffer* buffer = | 42 OverlappedBuffer* buffer = |
| 37 new(buffer_size) OverlappedBuffer(buffer_size, operation); | 43 new(actual_size) OverlappedBuffer(actual_size, operation); |
| 38 return buffer; | 44 return buffer; |
| 39 } | 45 } |
| 40 | 46 |
| 41 | 47 |
| 42 OverlappedBuffer* OverlappedBuffer::AllocateAcceptBuffer(int buffer_size) { | 48 OverlappedBuffer* OverlappedBuffer::AllocateAcceptBuffer(int buffer_size) { |
| 43 OverlappedBuffer* buffer = AllocateBuffer(buffer_size, kAccept); | 49 OverlappedBuffer* buffer = AllocateBuffer(buffer_size, kAccept); |
| 44 return buffer; | 50 return buffer; |
| 45 } | 51 } |
| 46 | 52 |
| 47 | 53 |
| 48 OverlappedBuffer* OverlappedBuffer::AllocateReadBuffer(int buffer_size) { | 54 OverlappedBuffer* OverlappedBuffer::AllocateReadBuffer(int buffer_size) { |
| 49 return AllocateBuffer(buffer_size, kRead); | 55 return AllocateBuffer(buffer_size, kRead); |
| 50 } | 56 } |
| 51 | 57 |
| 52 | 58 |
| 59 OverlappedBuffer* OverlappedBuffer::AllocateRecvFromBuffer(int buffer_size) { | |
| 60 return AllocateBuffer(buffer_size, kRecvFrom); | |
| 61 } | |
| 62 | |
| 63 | |
| 53 OverlappedBuffer* OverlappedBuffer::AllocateWriteBuffer(int buffer_size) { | 64 OverlappedBuffer* OverlappedBuffer::AllocateWriteBuffer(int buffer_size) { |
| 54 return AllocateBuffer(buffer_size, kWrite); | 65 return AllocateBuffer(buffer_size, kWrite); |
| 55 } | 66 } |
| 56 | 67 |
| 57 | 68 |
| 69 OverlappedBuffer* OverlappedBuffer::AllocateSendToBuffer(int buffer_size) { | |
| 70 return AllocateBuffer(buffer_size, kSendTo); | |
| 71 } | |
| 72 | |
| 73 | |
| 58 OverlappedBuffer* OverlappedBuffer::AllocateDisconnectBuffer() { | 74 OverlappedBuffer* OverlappedBuffer::AllocateDisconnectBuffer() { |
| 59 return AllocateBuffer(0, kDisconnect); | 75 return AllocateBuffer(0, kDisconnect); |
| 60 } | 76 } |
| 61 | 77 |
| 62 | 78 |
| 63 void OverlappedBuffer::DisposeBuffer(OverlappedBuffer* buffer) { | 79 void OverlappedBuffer::DisposeBuffer(OverlappedBuffer* buffer) { |
| 64 delete buffer; | 80 delete buffer; |
| 65 } | 81 } |
| 66 | 82 |
| 67 | 83 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 84 | 100 |
| 85 int OverlappedBuffer::Write(const void* buffer, int num_bytes) { | 101 int OverlappedBuffer::Write(const void* buffer, int num_bytes) { |
| 86 ASSERT(num_bytes == buflen_); | 102 ASSERT(num_bytes == buflen_); |
| 87 memmove(GetBufferStart(), buffer, num_bytes); | 103 memmove(GetBufferStart(), buffer, num_bytes); |
| 88 data_length_ = num_bytes; | 104 data_length_ = num_bytes; |
| 89 return num_bytes; | 105 return num_bytes; |
| 90 } | 106 } |
| 91 | 107 |
| 92 | 108 |
| 93 int OverlappedBuffer::GetRemainingLength() { | 109 int OverlappedBuffer::GetRemainingLength() { |
| 94 ASSERT(operation_ == kRead); | 110 ASSERT(operation_ == kRead || operation_ == kRecvFrom); |
| 95 return data_length_ - index_; | 111 return data_length_ - index_; |
| 96 } | 112 } |
| 97 | 113 |
| 98 | 114 |
| 99 Handle::Handle(HANDLE handle) | 115 Handle::Handle(HANDLE handle) |
| 100 : handle_(reinterpret_cast<HANDLE>(handle)), | 116 : handle_(reinterpret_cast<HANDLE>(handle)), |
| 101 port_(0), | 117 port_(0), |
| 102 mask_(0), | 118 mask_(0), |
| 103 completion_port_(INVALID_HANDLE_VALUE), | 119 completion_port_(INVALID_HANDLE_VALUE), |
| 104 event_handler_(NULL), | 120 event_handler_(NULL), |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 ASSERT(data_ready_ == NULL); | 208 ASSERT(data_ready_ == NULL); |
| 193 if (!IsClosing() && !buffer->IsEmpty()) { | 209 if (!IsClosing() && !buffer->IsEmpty()) { |
| 194 data_ready_ = pending_read_; | 210 data_ready_ = pending_read_; |
| 195 } else { | 211 } else { |
| 196 OverlappedBuffer::DisposeBuffer(buffer); | 212 OverlappedBuffer::DisposeBuffer(buffer); |
| 197 } | 213 } |
| 198 pending_read_ = NULL; | 214 pending_read_ = NULL; |
| 199 } | 215 } |
| 200 | 216 |
| 201 | 217 |
| 218 void Handle::RecvFromComplete(OverlappedBuffer* buffer) { | |
| 219 ReadComplete(buffer); | |
| 220 } | |
| 221 | |
| 222 | |
| 202 void Handle::WriteComplete(OverlappedBuffer* buffer) { | 223 void Handle::WriteComplete(OverlappedBuffer* buffer) { |
| 203 ScopedLock lock(this); | 224 ScopedLock lock(this); |
| 204 // Currently only one outstanding write at the time. | 225 // Currently only one outstanding write at the time. |
| 205 ASSERT(pending_write_ == buffer); | 226 ASSERT(pending_write_ == buffer); |
| 206 OverlappedBuffer::DisposeBuffer(buffer); | 227 OverlappedBuffer::DisposeBuffer(buffer); |
| 207 pending_write_ = NULL; | 228 pending_write_ = NULL; |
| 208 } | 229 } |
| 209 | 230 |
| 210 | 231 |
| 211 static void ReadFileThread(uword args) { | 232 static void ReadFileThread(uword args) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 int result = dart::Thread::Start(ReadFileThread, | 293 int result = dart::Thread::Start(ReadFileThread, |
| 273 reinterpret_cast<uword>(this)); | 294 reinterpret_cast<uword>(this)); |
| 274 if (result != 0) { | 295 if (result != 0) { |
| 275 FATAL1("Failed to start read file thread %d", result); | 296 FATAL1("Failed to start read file thread %d", result); |
| 276 } | 297 } |
| 277 return true; | 298 return true; |
| 278 } | 299 } |
| 279 } | 300 } |
| 280 | 301 |
| 281 | 302 |
| 303 bool Handle::IssueRecvFrom() { | |
| 304 return false; | |
| 305 } | |
| 306 | |
| 307 | |
| 282 bool Handle::IssueWrite() { | 308 bool Handle::IssueWrite() { |
| 283 ScopedLock lock(this); | 309 ScopedLock lock(this); |
| 284 ASSERT(type_ != kListenSocket); | 310 ASSERT(type_ != kListenSocket); |
| 285 ASSERT(completion_port_ != INVALID_HANDLE_VALUE); | 311 ASSERT(completion_port_ != INVALID_HANDLE_VALUE); |
| 286 ASSERT(pending_write_ != NULL); | 312 ASSERT(pending_write_ != NULL); |
| 287 ASSERT(pending_write_->operation() == OverlappedBuffer::kWrite); | 313 ASSERT(pending_write_->operation() == OverlappedBuffer::kWrite); |
| 288 | 314 |
| 289 OverlappedBuffer* buffer = pending_write_; | 315 OverlappedBuffer* buffer = pending_write_; |
| 290 BOOL ok = WriteFile(handle_, | 316 BOOL ok = WriteFile(handle_, |
| 291 buffer->GetBufferStart(), | 317 buffer->GetBufferStart(), |
| 292 buffer->GetBufferSize(), | 318 buffer->GetBufferSize(), |
| 293 NULL, | 319 NULL, |
| 294 buffer->GetCleanOverlapped()); | 320 buffer->GetCleanOverlapped()); |
| 295 if (ok || GetLastError() == ERROR_IO_PENDING) { | 321 if (ok || GetLastError() == ERROR_IO_PENDING) { |
| 296 // Completing asynchronously. | 322 // Completing asynchronously. |
| 297 pending_write_ = buffer; | 323 pending_write_ = buffer; |
| 298 return true; | 324 return true; |
| 299 } | 325 } |
| 300 OverlappedBuffer::DisposeBuffer(buffer); | 326 OverlappedBuffer::DisposeBuffer(buffer); |
| 301 HandleIssueError(); | 327 HandleIssueError(); |
| 302 return false; | 328 return false; |
| 303 } | 329 } |
| 304 | 330 |
| 305 | 331 |
| 332 bool Handle::IssueSendTo(struct sockaddr* sa, socklen_t sa_len) { | |
| 333 return false; | |
| 334 } | |
| 335 | |
| 336 | |
| 306 void Handle::HandleIssueError() { | 337 void Handle::HandleIssueError() { |
| 307 DWORD error = GetLastError(); | 338 DWORD error = GetLastError(); |
| 308 if (error == ERROR_BROKEN_PIPE) { | 339 if (error == ERROR_BROKEN_PIPE) { |
| 309 event_handler_->HandleClosed(this); | 340 event_handler_->HandleClosed(this); |
| 310 } else { | 341 } else { |
| 311 event_handler_->HandleError(this); | 342 event_handler_->HandleError(this); |
| 312 } | 343 } |
| 313 SetLastError(error); | 344 SetLastError(error); |
| 314 } | 345 } |
| 315 | 346 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 536 if (data_ready_ == NULL) return 0; | 567 if (data_ready_ == NULL) return 0; |
| 537 num_bytes = data_ready_->Read(buffer, num_bytes); | 568 num_bytes = data_ready_->Read(buffer, num_bytes); |
| 538 if (data_ready_->IsEmpty()) { | 569 if (data_ready_->IsEmpty()) { |
| 539 OverlappedBuffer::DisposeBuffer(data_ready_); | 570 OverlappedBuffer::DisposeBuffer(data_ready_); |
| 540 data_ready_ = NULL; | 571 data_ready_ = NULL; |
| 541 } | 572 } |
| 542 return num_bytes; | 573 return num_bytes; |
| 543 } | 574 } |
| 544 | 575 |
| 545 | 576 |
| 577 int Handle::RecvFrom( | |
| 578 void* buffer, int num_bytes, struct sockaddr* sa, socklen_t sa_len) { | |
| 579 ScopedLock lock(this); | |
| 580 if (data_ready_ == NULL) return 0; | |
| 581 num_bytes = data_ready_->Read(buffer, num_bytes); | |
|
Anders Johnsen
2013/12/12 12:19:58
Will this allow us to read only a part of a UDP pa
Søren Gjesse
2013/12/12 15:44:39
It will, I changed it to dispose of the rest, so t
| |
| 582 if (data_ready_->from()->sa_family == AF_INET) { | |
| 583 ASSERT(sa_len >= sizeof(struct sockaddr_in)); | |
| 584 memmove(sa, data_ready_->from(), sizeof(struct sockaddr_in)); | |
| 585 } else { | |
| 586 ASSERT(data_ready_->from()->sa_family == AF_INET6); | |
| 587 ASSERT(sa_len >= sizeof(struct sockaddr_in6)); | |
| 588 memmove(sa, data_ready_->from(), sizeof(struct sockaddr_in6)); | |
| 589 } | |
| 590 if (data_ready_->IsEmpty()) { | |
| 591 OverlappedBuffer::DisposeBuffer(data_ready_); | |
| 592 data_ready_ = NULL; | |
| 593 } | |
| 594 return num_bytes; | |
| 595 } | |
| 596 | |
| 597 | |
| 546 int Handle::Write(const void* buffer, int num_bytes) { | 598 int Handle::Write(const void* buffer, int num_bytes) { |
| 547 ScopedLock lock(this); | 599 ScopedLock lock(this); |
| 548 if (pending_write_ != NULL) return 0; | 600 if (pending_write_ != NULL) return 0; |
| 549 if (num_bytes > kBufferSize) num_bytes = kBufferSize; | 601 if (num_bytes > kBufferSize) num_bytes = kBufferSize; |
| 550 ASSERT(SupportsOverlappedIO()); | 602 ASSERT(SupportsOverlappedIO()); |
| 551 if (completion_port_ == INVALID_HANDLE_VALUE) return 0; | 603 if (completion_port_ == INVALID_HANDLE_VALUE) return 0; |
| 552 pending_write_ = OverlappedBuffer::AllocateWriteBuffer(num_bytes); | 604 pending_write_ = OverlappedBuffer::AllocateWriteBuffer(num_bytes); |
| 553 pending_write_->Write(buffer, num_bytes); | 605 pending_write_->Write(buffer, num_bytes); |
| 554 if (!IssueWrite()) return -1; | 606 if (!IssueWrite()) return -1; |
| 555 return num_bytes; | 607 return num_bytes; |
| 556 } | 608 } |
| 557 | 609 |
| 558 | 610 |
| 611 int Handle::SendTo( | |
| 612 const void* buffer, int num_bytes, struct sockaddr* sa, socklen_t sa_len) { | |
| 613 ScopedLock lock(this); | |
| 614 if (pending_write_ != NULL) return 0; | |
| 615 if (num_bytes > kBufferSize) num_bytes = kBufferSize; | |
| 616 ASSERT(SupportsOverlappedIO()); | |
| 617 if (completion_port_ == INVALID_HANDLE_VALUE) return 0; | |
| 618 pending_write_ = OverlappedBuffer::AllocateSendToBuffer(num_bytes); | |
| 619 pending_write_->Write(buffer, num_bytes); | |
| 620 if (!IssueSendTo(sa, sa_len)) return -1; | |
|
Anders Johnsen
2013/12/12 12:19:58
Can this leak the pending_write?
Søren Gjesse
2013/12/12 15:44:39
No, IssueSendTo will dispose of it before returnin
| |
| 621 return num_bytes; | |
| 622 } | |
| 623 | |
| 624 | |
| 559 static void WriteFileThread(uword args) { | 625 static void WriteFileThread(uword args) { |
| 560 StdHandle* handle = reinterpret_cast<StdHandle*>(args); | 626 StdHandle* handle = reinterpret_cast<StdHandle*>(args); |
| 561 handle->RunWriteLoop(); | 627 handle->RunWriteLoop(); |
| 562 } | 628 } |
| 563 | 629 |
| 564 | 630 |
| 565 void StdHandle::RunWriteLoop() { | 631 void StdHandle::RunWriteLoop() { |
| 566 write_monitor_->Enter(); | 632 write_monitor_->Enter(); |
| 567 write_thread_running_ = true; | 633 write_thread_running_ = true; |
| 568 // Notify we have started. | 634 // Notify we have started. |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 700 shutdown(socket(), SD_BOTH); | 766 shutdown(socket(), SD_BOTH); |
| 701 IssueDisconnect(); | 767 IssueDisconnect(); |
| 702 } | 768 } |
| 703 | 769 |
| 704 | 770 |
| 705 bool ClientSocket::IssueRead() { | 771 bool ClientSocket::IssueRead() { |
| 706 ScopedLock lock(this); | 772 ScopedLock lock(this); |
| 707 ASSERT(completion_port_ != INVALID_HANDLE_VALUE); | 773 ASSERT(completion_port_ != INVALID_HANDLE_VALUE); |
| 708 ASSERT(pending_read_ == NULL); | 774 ASSERT(pending_read_ == NULL); |
| 709 | 775 |
| 710 OverlappedBuffer* buffer = OverlappedBuffer::AllocateReadBuffer(1024); | 776 // TODO(sgjesse): Use a MTU value here. Only the loopback adapter can |
| 777 // handle 64k datagrams. | |
| 778 OverlappedBuffer* buffer = OverlappedBuffer::AllocateReadBuffer(65536); | |
| 711 | 779 |
| 712 DWORD flags; | 780 DWORD flags; |
| 713 flags = 0; | 781 flags = 0; |
| 714 int rc = WSARecv(socket(), | 782 int rc = WSARecv(socket(), |
| 715 buffer->GetWASBUF(), | 783 buffer->GetWASBUF(), |
| 716 1, | 784 1, |
| 717 NULL, | 785 NULL, |
| 718 &flags, | 786 &flags, |
| 719 buffer->GetCleanOverlapped(), | 787 buffer->GetCleanOverlapped(), |
| 720 NULL); | 788 NULL); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 784 CreateCompletionPort(event_handler_->completion_port()); | 852 CreateCompletionPort(event_handler_->completion_port()); |
| 785 } | 853 } |
| 786 } | 854 } |
| 787 | 855 |
| 788 | 856 |
| 789 bool ClientSocket::IsClosed() { | 857 bool ClientSocket::IsClosed() { |
| 790 return false; | 858 return false; |
| 791 } | 859 } |
| 792 | 860 |
| 793 | 861 |
| 862 bool DatagramSocket::IssueSendTo(struct sockaddr* sa, socklen_t sa_len) { | |
| 863 ScopedLock lock(this); | |
| 864 ASSERT(completion_port_ != INVALID_HANDLE_VALUE); | |
| 865 ASSERT(pending_write_ != NULL); | |
| 866 ASSERT(pending_write_->operation() == OverlappedBuffer::kSendTo); | |
| 867 | |
| 868 int rc = WSASendTo(socket(), | |
| 869 pending_write_->GetWASBUF(), | |
| 870 1, | |
| 871 NULL, | |
| 872 0, | |
| 873 sa, | |
| 874 sa_len, | |
| 875 pending_write_->GetCleanOverlapped(), | |
| 876 NULL); | |
| 877 if (rc == NO_ERROR || WSAGetLastError() == WSA_IO_PENDING) { | |
| 878 return true; | |
| 879 } | |
| 880 OverlappedBuffer::DisposeBuffer(pending_write_); | |
| 881 pending_write_ = NULL; | |
| 882 HandleIssueError(); | |
| 883 return false; | |
| 884 } | |
| 885 | |
| 886 | |
| 887 bool DatagramSocket::IssueRecvFrom() { | |
| 888 ScopedLock lock(this); | |
| 889 ASSERT(completion_port_ != INVALID_HANDLE_VALUE); | |
| 890 ASSERT(pending_read_ == NULL); | |
| 891 | |
| 892 OverlappedBuffer* buffer = OverlappedBuffer::AllocateRecvFromBuffer(1024); | |
| 893 | |
| 894 DWORD flags; | |
| 895 flags = 0; | |
| 896 int len; | |
| 897 int rc = WSARecvFrom(socket(), | |
| 898 buffer->GetWASBUF(), | |
| 899 1, | |
| 900 NULL, | |
| 901 &flags, | |
| 902 buffer->from(), | |
| 903 buffer->from_len_addr(), | |
| 904 buffer->GetCleanOverlapped(), | |
| 905 NULL); | |
| 906 if (rc == NO_ERROR || WSAGetLastError() == WSA_IO_PENDING) { | |
| 907 pending_read_ = buffer; | |
| 908 return true; | |
| 909 } | |
| 910 OverlappedBuffer::DisposeBuffer(buffer); | |
| 911 pending_read_ = NULL; | |
| 912 HandleIssueError(); | |
| 913 return false; | |
| 914 } | |
| 915 | |
| 916 | |
| 917 void DatagramSocket::EnsureInitialized( | |
| 918 EventHandlerImplementation* event_handler) { | |
| 919 ScopedLock lock(this); | |
| 920 if (completion_port_ == INVALID_HANDLE_VALUE) { | |
| 921 ASSERT(event_handler_ == NULL); | |
| 922 event_handler_ = event_handler; | |
| 923 CreateCompletionPort(event_handler_->completion_port()); | |
| 924 } | |
| 925 } | |
| 926 | |
| 927 | |
| 928 bool DatagramSocket::IsClosed() { | |
| 929 return IsClosing() && !HasPendingRead() && !HasPendingWrite(); | |
| 930 } | |
| 931 | |
| 932 | |
| 933 void DatagramSocket::DoClose() { | |
| 934 // Just close the socket. This will cause any queued requests to be aborted. | |
| 935 closesocket(socket()); | |
| 936 MarkClosedRead(); | |
| 937 MarkClosedWrite(); | |
| 938 } | |
| 939 | |
| 940 | |
| 794 static void DeleteIfClosed(Handle* handle) { | 941 static void DeleteIfClosed(Handle* handle) { |
| 795 if (handle->IsClosed()) { | 942 if (handle->IsClosed()) { |
| 796 Dart_Port port = handle->port(); | 943 Dart_Port port = handle->port(); |
| 797 delete handle; | 944 delete handle; |
| 798 DartUtils::PostInt32(port, 1 << kDestroyedEvent); | 945 DartUtils::PostInt32(port, 1 << kDestroyedEvent); |
| 799 } | 946 } |
| 800 } | 947 } |
| 801 | 948 |
| 802 | 949 |
| 803 void EventHandlerImplementation::HandleInterrupt(InterruptMessage* msg) { | 950 void EventHandlerImplementation::HandleInterrupt(InterruptMessage* msg) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 851 // for read. | 998 // for read. |
| 852 if ((msg->data & (1 << kInEvent)) != 0) { | 999 if ((msg->data & (1 << kInEvent)) != 0) { |
| 853 if (handle->Available() > 0) { | 1000 if (handle->Available() > 0) { |
| 854 int event_mask = (1 << kInEvent); | 1001 int event_mask = (1 << kInEvent); |
| 855 handle->set_mask(handle->mask() & ~event_mask); | 1002 handle->set_mask(handle->mask() & ~event_mask); |
| 856 DartUtils::PostInt32(handle->port(), event_mask); | 1003 DartUtils::PostInt32(handle->port(), event_mask); |
| 857 } else if (handle->IsClosedRead()) { | 1004 } else if (handle->IsClosedRead()) { |
| 858 int event_mask = (1 << kCloseEvent); | 1005 int event_mask = (1 << kCloseEvent); |
| 859 DartUtils::PostInt32(handle->port(), event_mask); | 1006 DartUtils::PostInt32(handle->port(), event_mask); |
| 860 } else if (!handle->HasPendingRead()) { | 1007 } else if (!handle->HasPendingRead()) { |
| 861 handle->IssueRead(); | 1008 if (handle->is_datagram_socket()) { |
| 1009 handle->IssueRecvFrom(); | |
| 1010 } else { | |
| 1011 handle->IssueRead(); | |
| 1012 } | |
| 862 } | 1013 } |
| 863 } | 1014 } |
| 864 | 1015 |
| 865 // If out events (can write events) have been requested, and there | 1016 // If out events (can write events) have been requested, and there |
| 866 // are no pending writes, post an out event immediately. | 1017 // are no pending writes, post an out event immediately. |
| 867 if ((msg->data & (1 << kOutEvent)) != 0) { | 1018 if ((msg->data & (1 << kOutEvent)) != 0) { |
| 868 if (!handle->HasPendingWrite()) { | 1019 if (!handle->HasPendingWrite()) { |
| 869 int event_mask = (1 << kOutEvent); | 1020 int event_mask = (1 << kOutEvent); |
| 870 handle->set_mask(handle->mask() & ~event_mask); | 1021 handle->set_mask(handle->mask() & ~event_mask); |
| 871 DartUtils::PostInt32(handle->port(), event_mask); | 1022 DartUtils::PostInt32(handle->port(), event_mask); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 946 HandleClosed(handle); | 1097 HandleClosed(handle); |
| 947 } else { | 1098 } else { |
| 948 HandleError(handle); | 1099 HandleError(handle); |
| 949 } | 1100 } |
| 950 } | 1101 } |
| 951 | 1102 |
| 952 DeleteIfClosed(handle); | 1103 DeleteIfClosed(handle); |
| 953 } | 1104 } |
| 954 | 1105 |
| 955 | 1106 |
| 1107 void EventHandlerImplementation::HandleRecvFrom(Handle* handle, | |
| 1108 int bytes, | |
| 1109 OverlappedBuffer* buffer) { | |
| 1110 ASSERT(handle->is_datagram_socket()); | |
| 1111 buffer->set_data_length(bytes); | |
| 1112 handle->ReadComplete(buffer); | |
| 1113 if (!handle->IsClosing()) { | |
| 1114 int event_mask = 1 << kInEvent; | |
| 1115 if ((handle->mask() & event_mask) != 0) { | |
| 1116 DartUtils::PostInt32(handle->port(), event_mask); | |
| 1117 } | |
| 1118 } | |
| 1119 | |
| 1120 DeleteIfClosed(handle); | |
| 1121 } | |
| 1122 | |
| 1123 | |
| 956 void EventHandlerImplementation::HandleWrite(Handle* handle, | 1124 void EventHandlerImplementation::HandleWrite(Handle* handle, |
| 957 int bytes, | 1125 int bytes, |
| 958 OverlappedBuffer* buffer) { | 1126 OverlappedBuffer* buffer) { |
| 959 handle->WriteComplete(buffer); | 1127 handle->WriteComplete(buffer); |
| 960 | 1128 |
| 961 if (bytes > 0) { | 1129 if (bytes > 0) { |
| 962 if (!handle->IsError() && !handle->IsClosing()) { | 1130 if (!handle->IsError() && !handle->IsClosing()) { |
| 963 int event_mask = 1 << kOutEvent; | 1131 int event_mask = 1 << kOutEvent; |
| 964 if ((handle->mask() & event_mask) != 0) { | 1132 if ((handle->mask() & event_mask) != 0) { |
| 965 DartUtils::PostInt32(handle->port(), event_mask); | 1133 DartUtils::PostInt32(handle->port(), event_mask); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 997 case OverlappedBuffer::kAccept: { | 1165 case OverlappedBuffer::kAccept: { |
| 998 ListenSocket* listen_socket = reinterpret_cast<ListenSocket*>(key); | 1166 ListenSocket* listen_socket = reinterpret_cast<ListenSocket*>(key); |
| 999 HandleAccept(listen_socket, buffer); | 1167 HandleAccept(listen_socket, buffer); |
| 1000 break; | 1168 break; |
| 1001 } | 1169 } |
| 1002 case OverlappedBuffer::kRead: { | 1170 case OverlappedBuffer::kRead: { |
| 1003 Handle* handle = reinterpret_cast<Handle*>(key); | 1171 Handle* handle = reinterpret_cast<Handle*>(key); |
| 1004 HandleRead(handle, bytes, buffer); | 1172 HandleRead(handle, bytes, buffer); |
| 1005 break; | 1173 break; |
| 1006 } | 1174 } |
| 1007 case OverlappedBuffer::kWrite: { | 1175 case OverlappedBuffer::kRecvFrom: { |
| 1176 Handle* handle = reinterpret_cast<Handle*>(key); | |
| 1177 HandleRecvFrom(handle, bytes, buffer); | |
| 1178 break; | |
| 1179 } | |
| 1180 case OverlappedBuffer::kWrite: | |
| 1181 case OverlappedBuffer::kSendTo: { | |
| 1008 Handle* handle = reinterpret_cast<Handle*>(key); | 1182 Handle* handle = reinterpret_cast<Handle*>(key); |
| 1009 HandleWrite(handle, bytes, buffer); | 1183 HandleWrite(handle, bytes, buffer); |
| 1010 break; | 1184 break; |
| 1011 } | 1185 } |
| 1012 case OverlappedBuffer::kDisconnect: { | 1186 case OverlappedBuffer::kDisconnect: { |
| 1013 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(key); | 1187 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(key); |
| 1014 HandleDisconnect(client_socket, bytes, buffer); | 1188 HandleDisconnect(client_socket, bytes, buffer); |
| 1015 break; | 1189 break; |
| 1016 } | 1190 } |
| 1017 default: | 1191 default: |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1094 // ERROR_NETNAME_DELETED occurs when the client closes | 1268 // ERROR_NETNAME_DELETED occurs when the client closes |
| 1095 // the socket it is reading from. | 1269 // the socket it is reading from. |
| 1096 DWORD last_error = GetLastError(); | 1270 DWORD last_error = GetLastError(); |
| 1097 if (last_error == ERROR_CONNECTION_ABORTED || | 1271 if (last_error == ERROR_CONNECTION_ABORTED || |
| 1098 last_error == ERROR_OPERATION_ABORTED || | 1272 last_error == ERROR_OPERATION_ABORTED || |
| 1099 last_error == ERROR_NETNAME_DELETED || | 1273 last_error == ERROR_NETNAME_DELETED || |
| 1100 last_error == ERROR_BROKEN_PIPE) { | 1274 last_error == ERROR_BROKEN_PIPE) { |
| 1101 ASSERT(bytes == 0); | 1275 ASSERT(bytes == 0); |
| 1102 handler_impl->HandleIOCompletion(bytes, key, overlapped); | 1276 handler_impl->HandleIOCompletion(bytes, key, overlapped); |
| 1103 } else { | 1277 } else { |
| 1278 OverlappedBuffer* buffer = | |
|
Anders Johnsen
2013/12/12 12:19:58
Unused?
Søren Gjesse
2013/12/12 15:44:39
Yes, removed.
| |
| 1279 OverlappedBuffer::GetFromOverlapped(overlapped); | |
| 1104 ASSERT(bytes == 0); | 1280 ASSERT(bytes == 0); |
| 1105 handler_impl->HandleIOCompletion(-1, key, overlapped); | 1281 handler_impl->HandleIOCompletion(-1, key, overlapped); |
| 1106 } | 1282 } |
| 1107 } else if (key == NULL) { | 1283 } else if (key == NULL) { |
| 1108 // A key of NULL signals an interrupt message. | 1284 // A key of NULL signals an interrupt message. |
| 1109 InterruptMessage* msg = reinterpret_cast<InterruptMessage*>(overlapped); | 1285 InterruptMessage* msg = reinterpret_cast<InterruptMessage*>(overlapped); |
| 1110 handler_impl->HandleInterrupt(msg); | 1286 handler_impl->HandleInterrupt(msg); |
| 1111 delete msg; | 1287 delete msg; |
| 1112 } else { | 1288 } else { |
| 1113 handler_impl->HandleIOCompletion(bytes, key, overlapped); | 1289 handler_impl->HandleIOCompletion(bytes, key, overlapped); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1132 | 1308 |
| 1133 | 1309 |
| 1134 void EventHandlerImplementation::Shutdown() { | 1310 void EventHandlerImplementation::Shutdown() { |
| 1135 SendData(kShutdownId, 0, 0); | 1311 SendData(kShutdownId, 0, 0); |
| 1136 } | 1312 } |
| 1137 | 1313 |
| 1138 } // namespace bin | 1314 } // namespace bin |
| 1139 } // namespace dart | 1315 } // namespace dart |
| 1140 | 1316 |
| 1141 #endif // defined(TARGET_OS_WINDOWS) | 1317 #endif // defined(TARGET_OS_WINDOWS) |
| OLD | NEW |