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

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

Issue 2803543006: Added synchronous socket implementation to dart:io. (Closed)
Patch Set: Small fix for MacOS Created 3 years, 8 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
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 #if !defined(DART_IO_DISABLED) 5 #if !defined(DART_IO_DISABLED)
6 6
7 #include "platform/globals.h" 7 #include "platform/globals.h"
8 #if defined(HOST_OS_WINDOWS) 8 #if defined(HOST_OS_WINDOWS)
9 9
10 #include "bin/eventhandler.h" 10 #include "bin/eventhandler.h"
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 MonitorLocker ml(monitor_); 930 MonitorLocker ml(monitor_);
931 ASSERT(completion_port_ != INVALID_HANDLE_VALUE); 931 ASSERT(completion_port_ != INVALID_HANDLE_VALUE);
932 ASSERT(pending_read_ == NULL); 932 ASSERT(pending_read_ == NULL);
933 933
934 // TODO(sgjesse): Use a MTU value here. Only the loopback adapter can 934 // TODO(sgjesse): Use a MTU value here. Only the loopback adapter can
935 // handle 64k datagrams. 935 // handle 64k datagrams.
936 OverlappedBuffer* buffer = OverlappedBuffer::AllocateReadBuffer(65536); 936 OverlappedBuffer* buffer = OverlappedBuffer::AllocateReadBuffer(65536);
937 937
938 DWORD flags; 938 DWORD flags;
939 flags = 0; 939 flags = 0;
940 OVERLAPPED* overlap_buffer = (sync ? NULL : buffer->GetCleanOverlapped());
940 int rc = WSARecv(socket(), buffer->GetWASBUF(), 1, NULL, &flags, 941 int rc = WSARecv(socket(), buffer->GetWASBUF(), 1, NULL, &flags,
941 buffer->GetCleanOverlapped(), NULL); 942 overlap_buffer, NULL);
942 if ((rc == NO_ERROR) || (WSAGetLastError() == WSA_IO_PENDING)) { 943 if ((rc == NO_ERROR) || (WSAGetLastError() == WSA_IO_PENDING)) {
943 pending_read_ = buffer; 944 pending_read_ = buffer;
944 return true; 945 return true;
945 } 946 }
946 OverlappedBuffer::DisposeBuffer(buffer); 947 OverlappedBuffer::DisposeBuffer(buffer);
947 pending_read_ = NULL; 948 pending_read_ = NULL;
948 HandleIssueError(); 949 HandleIssueError();
949 return false; 950 return false;
950 } 951 }
951 952
952 953
953 bool ClientSocket::IssueWrite() { 954 bool ClientSocket::IssueWrite() {
954 MonitorLocker ml(monitor_); 955 MonitorLocker ml(monitor_);
955 ASSERT(completion_port_ != INVALID_HANDLE_VALUE); 956 ASSERT(completion_port_ != INVALID_HANDLE_VALUE);
956 ASSERT(pending_write_ != NULL); 957 ASSERT(pending_write_ != NULL);
957 ASSERT(pending_write_->operation() == OverlappedBuffer::kWrite); 958 ASSERT(pending_write_->operation() == OverlappedBuffer::kWrite);
958 959
960 OVERLAPPED* overlap_buffer =
961 (sync ? NULL : pending_write->GetCleanOverlapped());
959 int rc = WSASend(socket(), pending_write_->GetWASBUF(), 1, NULL, 0, 962 int rc = WSASend(socket(), pending_write_->GetWASBUF(), 1, NULL, 0,
960 pending_write_->GetCleanOverlapped(), NULL); 963 overlap_buffer, NULL);
961 if ((rc == NO_ERROR) || (WSAGetLastError() == WSA_IO_PENDING)) { 964 if ((rc == NO_ERROR) || (WSAGetLastError() == WSA_IO_PENDING)) {
962 return true; 965 return true;
963 } 966 }
964 OverlappedBuffer::DisposeBuffer(pending_write_); 967 OverlappedBuffer::DisposeBuffer(pending_write_);
965 pending_write_ = NULL; 968 pending_write_ = NULL;
966 HandleIssueError(); 969 HandleIssueError();
967 return false; 970 return false;
968 } 971 }
969 972
970 973
971 void ClientSocket::IssueDisconnect() { 974 void ClientSocket::IssueDisconnect() {
972 OverlappedBuffer* buffer = OverlappedBuffer::AllocateDisconnectBuffer(); 975 OverlappedBuffer* buffer = OverlappedBuffer::AllocateDisconnectBuffer();
973 BOOL ok = 976 OVERLAPPED* overlap_buffer = (sync ? NULL : buffer->GetCleanOverlapped());
974 DisconnectEx_(socket(), buffer->GetCleanOverlapped(), TF_REUSE_SOCKET, 0); 977 BOOL ok = DisconnectEx_(socket(), overlap_buffer, TF_REUSE_SOCKET, 0);
975 // DisconnectEx works like other OverlappedIO APIs, where we can get either an 978 // DisconnectEx works like other OverlappedIO APIs, where we can get either an
976 // immediate success or delayed operation by WSA_IO_PENDING being set. 979 // immediate success or delayed operation by WSA_IO_PENDING being set.
977 if (ok || (WSAGetLastError() != WSA_IO_PENDING)) { 980 if (ok || (WSAGetLastError() != WSA_IO_PENDING)) {
978 DisconnectComplete(buffer); 981 DisconnectComplete(buffer);
979 } 982 }
980 // When the Dart side receives this event, it may decide to close its Dart 983 // When the Dart side receives this event, it may decide to close its Dart
981 // ports. When all ports are closed, the VM will shut down. The EventHandler 984 // ports. When all ports are closed, the VM will shut down. The EventHandler
982 // will then shut down. If the EventHandler shuts down before this 985 // will then shut down. If the EventHandler shuts down before this
983 // asynchronous disconnect finishes, this ClientSocket will be leaked. 986 // asynchronous disconnect finishes, this ClientSocket will be leaked.
984 // TODO(dart:io): Retain a list of client sockets that are in the process of 987 // TODO(dart:io): Retain a list of client sockets that are in the process of
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
1579 void EventHandlerImplementation::Shutdown() { 1582 void EventHandlerImplementation::Shutdown() {
1580 SendData(kShutdownId, 0, 0); 1583 SendData(kShutdownId, 0, 0);
1581 } 1584 }
1582 1585
1583 } // namespace bin 1586 } // namespace bin
1584 } // namespace dart 1587 } // namespace dart
1585 1588
1586 #endif // defined(HOST_OS_WINDOWS) 1589 #endif // defined(HOST_OS_WINDOWS)
1587 1590
1588 #endif // !defined(DART_IO_DISABLED) 1591 #endif // !defined(DART_IO_DISABLED)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698