OLD | NEW |
---|---|
1 // Copyright (c) 2012, 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 <process.h> // NOLINT | 10 #include <process.h> // NOLINT |
11 #include <winsock2.h> // NOLINT | 11 #include <winsock2.h> // NOLINT |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 void FileHandle::EnsureInitialized(EventHandlerImplementation* event_handler) { | 317 void FileHandle::EnsureInitialized(EventHandlerImplementation* event_handler) { |
318 ScopedLock lock(this); | 318 ScopedLock lock(this); |
319 event_handler_ = event_handler; | 319 event_handler_ = event_handler; |
320 if (SupportsOverlappedIO() && completion_port_ == INVALID_HANDLE_VALUE) { | 320 if (SupportsOverlappedIO() && completion_port_ == INVALID_HANDLE_VALUE) { |
321 CreateCompletionPort(event_handler_->completion_port()); | 321 CreateCompletionPort(event_handler_->completion_port()); |
322 } | 322 } |
323 } | 323 } |
324 | 324 |
325 | 325 |
326 bool FileHandle::IsClosed() { | 326 bool FileHandle::IsClosed() { |
327 return false; | 327 return IsClosing(); |
328 } | 328 } |
329 | 329 |
330 | 330 |
331 void FileHandle::DoClose() { | 331 void FileHandle::DoClose() { |
332 if (GetStdHandle(STD_OUTPUT_HANDLE) == handle_) { | 332 if (GetStdHandle(STD_OUTPUT_HANDLE) == handle_) { |
333 int fd = _open("NUL", _O_WRONLY); | 333 int fd = _open("NUL", _O_WRONLY); |
334 ASSERT(fd >= 0); | 334 ASSERT(fd >= 0); |
335 _dup2(fd, _fileno(stdout)); | 335 _dup2(fd, _fileno(stdout)); |
336 close(fd); | 336 close(fd); |
337 } else { | 337 } else { |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
566 if (how == SD_RECEIVE) MarkClosedRead(); | 566 if (how == SD_RECEIVE) MarkClosedRead(); |
567 if (how == SD_SEND) MarkClosedWrite(); | 567 if (how == SD_SEND) MarkClosedWrite(); |
568 if (how == SD_BOTH) { | 568 if (how == SD_BOTH) { |
569 MarkClosedRead(); | 569 MarkClosedRead(); |
570 MarkClosedWrite(); | 570 MarkClosedWrite(); |
571 } | 571 } |
572 } | 572 } |
573 | 573 |
574 | 574 |
575 void ClientSocket::DoClose() { | 575 void ClientSocket::DoClose() { |
576 // Always do a suhtdown before initiating a disconnect. | 576 // Always do a shutdown before initiating a disconnect. |
577 shutdown(socket(), SD_BOTH); | 577 shutdown(socket(), SD_BOTH); |
578 IssueDisconnect(); | 578 IssueDisconnect(); |
579 } | 579 } |
580 | 580 |
581 | 581 |
582 bool ClientSocket::IssueRead() { | 582 bool ClientSocket::IssueRead() { |
583 ScopedLock lock(this); | 583 ScopedLock lock(this); |
584 ASSERT(completion_port_ != INVALID_HANDLE_VALUE); | 584 ASSERT(completion_port_ != INVALID_HANDLE_VALUE); |
585 ASSERT(pending_read_ == NULL); | 585 ASSERT(pending_read_ == NULL); |
586 | 586 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
623 return true; | 623 return true; |
624 } | 624 } |
625 IOBuffer::DisposeBuffer(pending_write_); | 625 IOBuffer::DisposeBuffer(pending_write_); |
626 pending_write_ = NULL; | 626 pending_write_ = NULL; |
627 HandleIssueError(); | 627 HandleIssueError(); |
628 return false; | 628 return false; |
629 } | 629 } |
630 | 630 |
631 | 631 |
632 void ClientSocket::IssueDisconnect() { | 632 void ClientSocket::IssueDisconnect() { |
633 Dart_Port p = port(); | |
633 IOBuffer* buffer = IOBuffer::AllocateDisconnectBuffer(); | 634 IOBuffer* buffer = IOBuffer::AllocateDisconnectBuffer(); |
634 BOOL ok = DisconnectEx_( | 635 BOOL ok = DisconnectEx_( |
635 socket(), buffer->GetCleanOverlapped(), TF_REUSE_SOCKET, 0); | 636 socket(), buffer->GetCleanOverlapped(), TF_REUSE_SOCKET, 0); |
636 if (!ok && WSAGetLastError() != WSA_IO_PENDING) { | 637 if (!ok && WSAGetLastError() != WSA_IO_PENDING) { |
637 DisconnectComplete(buffer); | 638 DisconnectComplete(buffer); |
638 } | 639 } |
640 if (p != ILLEGAL_PORT) DartUtils::PostInt32(p, 1 << kDestroyedEvent); | |
kustermann
2013/07/18 11:34:46
If you closed a socket with 'DisconnectEx_' then y
Anders Johnsen
2013/07/19 10:49:07
In Socket::Connect we can end up creating a socket
| |
639 } | 641 } |
640 | 642 |
641 | 643 |
642 void ClientSocket::DisconnectComplete(IOBuffer* buffer) { | 644 void ClientSocket::DisconnectComplete(IOBuffer* buffer) { |
643 IOBuffer::DisposeBuffer(buffer); | 645 IOBuffer::DisposeBuffer(buffer); |
644 closesocket(socket()); | 646 closesocket(socket()); |
645 if (data_ready_ != NULL) { | 647 if (data_ready_ != NULL) { |
646 IOBuffer::DisposeBuffer(data_ready_); | 648 IOBuffer::DisposeBuffer(data_ready_); |
647 } | 649 } |
648 // When disconnect is complete get rid of the object. | 650 // When disconnect is complete get rid of the object. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
749 client_socket->Shutdown(SD_RECEIVE); | 751 client_socket->Shutdown(SD_RECEIVE); |
750 } | 752 } |
751 | 753 |
752 if ((msg->data & (1 << kShutdownWriteCommand)) != 0) { | 754 if ((msg->data & (1 << kShutdownWriteCommand)) != 0) { |
753 client_socket->Shutdown(SD_SEND); | 755 client_socket->Shutdown(SD_SEND); |
754 } | 756 } |
755 } | 757 } |
756 } | 758 } |
757 | 759 |
758 if ((msg->data & (1 << kCloseCommand)) != 0) { | 760 if ((msg->data & (1 << kCloseCommand)) != 0) { |
761 handle->SetPortAndMask(msg->dart_port, msg->data); | |
759 handle->Close(); | 762 handle->Close(); |
kustermann
2013/07/18 11:34:46
I thought 'handle->Close()' will result in 'IssueD
Anders Johnsen
2013/07/19 10:49:07
It will, but this is for more kinds than just Clie
| |
760 if (handle->IsClosed()) { | 763 if (handle->IsClosed()) { |
761 delete_handle = true; | 764 delete_handle = true; |
762 } | 765 } |
763 } | 766 } |
764 } | 767 } |
765 if (delete_handle) { | 768 if (delete_handle) { |
769 Dart_Port port = handle->port(); | |
766 delete handle; | 770 delete handle; |
771 DartUtils::PostInt32(port, 1 << kDestroyedEvent); | |
kustermann
2013/07/18 11:34:46
Why do you do it here again?
Anders Johnsen
2013/07/19 10:49:07
ClientSocket will never be delete any other place
| |
767 } | 772 } |
768 } | 773 } |
769 } | 774 } |
770 | 775 |
771 | 776 |
772 void EventHandlerImplementation::HandleAccept(ListenSocket* listen_socket, | 777 void EventHandlerImplementation::HandleAccept(ListenSocket* listen_socket, |
773 IOBuffer* buffer) { | 778 IOBuffer* buffer) { |
774 listen_socket->AcceptComplete(buffer, completion_port_); | 779 listen_socket->AcceptComplete(buffer, completion_port_); |
775 | 780 |
776 if (!listen_socket->IsClosing()) { | 781 if (!listen_socket->IsClosing()) { |
777 int event_mask = 1 << kInEvent; | 782 int event_mask = 1 << kInEvent; |
778 if ((listen_socket->mask() & event_mask) != 0) { | 783 if ((listen_socket->mask() & event_mask) != 0) { |
779 DartUtils::PostInt32(listen_socket->port(), event_mask); | 784 DartUtils::PostInt32(listen_socket->port(), event_mask); |
780 } | 785 } |
781 } | 786 } |
782 | 787 |
783 if (listen_socket->IsClosed()) { | 788 if (listen_socket->IsClosed()) { |
789 Dart_Port port = listen_socket->port(); | |
784 delete listen_socket; | 790 delete listen_socket; |
791 DartUtils::PostInt32(port, 1 << kDestroyedEvent); | |
kustermann
2013/07/18 11:34:46
I don't understand why these PostInt32(kDestroyEve
Anders Johnsen
2013/07/19 10:49:07
Every time we delete a socket, we send a destroy e
| |
785 } | 792 } |
786 } | 793 } |
787 | 794 |
788 | 795 |
789 void EventHandlerImplementation::HandleClosed(Handle* handle) { | 796 void EventHandlerImplementation::HandleClosed(Handle* handle) { |
790 if (!handle->IsClosing()) { | 797 if (!handle->IsClosing()) { |
791 int event_mask = 1 << kCloseEvent; | 798 int event_mask = 1 << kCloseEvent; |
792 DartUtils::PostInt32(handle->port(), event_mask); | 799 DartUtils::PostInt32(handle->port(), event_mask); |
793 } | 800 } |
794 } | 801 } |
(...skipping 24 matching lines...) Expand all Loading... | |
819 } else { | 826 } else { |
820 handle->MarkClosedRead(); | 827 handle->MarkClosedRead(); |
821 if (bytes == 0) { | 828 if (bytes == 0) { |
822 HandleClosed(handle); | 829 HandleClosed(handle); |
823 } else { | 830 } else { |
824 HandleError(handle); | 831 HandleError(handle); |
825 } | 832 } |
826 } | 833 } |
827 | 834 |
828 if (handle->IsClosed()) { | 835 if (handle->IsClosed()) { |
836 Dart_Port port = handle->port(); | |
829 delete handle; | 837 delete handle; |
838 DartUtils::PostInt32(port, 1 << kDestroyedEvent); | |
830 } | 839 } |
831 } | 840 } |
832 | 841 |
833 | 842 |
834 void EventHandlerImplementation::HandleWrite(Handle* handle, | 843 void EventHandlerImplementation::HandleWrite(Handle* handle, |
835 int bytes, | 844 int bytes, |
836 IOBuffer* buffer) { | 845 IOBuffer* buffer) { |
837 handle->WriteComplete(buffer); | 846 handle->WriteComplete(buffer); |
838 | 847 |
839 if (bytes > 0) { | 848 if (bytes > 0) { |
840 if (!handle->IsError() && !handle->IsClosing()) { | 849 if (!handle->IsError() && !handle->IsClosing()) { |
841 int event_mask = 1 << kOutEvent; | 850 int event_mask = 1 << kOutEvent; |
842 if ((handle->mask() & event_mask) != 0) { | 851 if ((handle->mask() & event_mask) != 0) { |
843 DartUtils::PostInt32(handle->port(), event_mask); | 852 DartUtils::PostInt32(handle->port(), event_mask); |
844 } | 853 } |
845 } | 854 } |
846 } else if (bytes == 0) { | 855 } else if (bytes == 0) { |
847 HandleClosed(handle); | 856 HandleClosed(handle); |
848 } else { | 857 } else { |
849 HandleError(handle); | 858 HandleError(handle); |
850 } | 859 } |
851 | 860 |
852 if (handle->IsClosed()) { | 861 if (handle->IsClosed()) { |
862 Dart_Port port = handle->port(); | |
853 delete handle; | 863 delete handle; |
864 DartUtils::PostInt32(port, 1 << kDestroyedEvent); | |
854 } | 865 } |
855 } | 866 } |
856 | 867 |
857 | 868 |
858 void EventHandlerImplementation::HandleDisconnect( | 869 void EventHandlerImplementation::HandleDisconnect( |
859 ClientSocket* client_socket, | 870 ClientSocket* client_socket, |
860 int bytes, | 871 int bytes, |
861 IOBuffer* buffer) { | 872 IOBuffer* buffer) { |
862 client_socket->DisconnectComplete(buffer); | 873 client_socket->DisconnectComplete(buffer); |
863 } | 874 } |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1012 | 1023 |
1013 | 1024 |
1014 void EventHandlerImplementation::Shutdown() { | 1025 void EventHandlerImplementation::Shutdown() { |
1015 SendData(kShutdownId, 0, 0); | 1026 SendData(kShutdownId, 0, 0); |
1016 } | 1027 } |
1017 | 1028 |
1018 } // namespace bin | 1029 } // namespace bin |
1019 } // namespace dart | 1030 } // namespace dart |
1020 | 1031 |
1021 #endif // defined(TARGET_OS_WINDOWS) | 1032 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |