| 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 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 OverlappedBuffer::DisposeBuffer(data_ready_); | 891 OverlappedBuffer::DisposeBuffer(data_ready_); |
| 892 } | 892 } |
| 893 closed_ = true; | 893 closed_ = true; |
| 894 } | 894 } |
| 895 | 895 |
| 896 | 896 |
| 897 void ClientSocket::ConnectComplete(OverlappedBuffer* buffer) { | 897 void ClientSocket::ConnectComplete(OverlappedBuffer* buffer) { |
| 898 OverlappedBuffer::DisposeBuffer(buffer); | 898 OverlappedBuffer::DisposeBuffer(buffer); |
| 899 // Update socket to support full socket API, after ConnectEx completed. | 899 // Update socket to support full socket API, after ConnectEx completed. |
| 900 setsockopt(socket(), SOL_SOCKET, SO_UPDATE_CONNECT_CONTEXT, NULL, 0); | 900 setsockopt(socket(), SOL_SOCKET, SO_UPDATE_CONNECT_CONTEXT, NULL, 0); |
| 901 connected_ = true; | |
| 902 Dart_Port p = port(); | 901 Dart_Port p = port(); |
| 903 if (p != ILLEGAL_PORT) { | 902 if (p != ILLEGAL_PORT) { |
| 904 // If the port is set, we already listen for this socket in Dart. | 903 // If the port is set, we already listen for this socket in Dart. |
| 905 // Handle the cases here. | 904 // Handle the cases here. |
| 906 if (!IsClosedRead()) { | 905 if (!IsClosedRead()) { |
| 907 IssueRead(); | 906 IssueRead(); |
| 908 } | 907 } |
| 909 if (!IsClosedWrite()) { | 908 if (!IsClosedWrite()) { |
| 910 DartUtils::PostInt32(p, 1 << kOutEvent); | 909 DartUtils::PostInt32(p, 1 << kOutEvent); |
| 911 } | 910 } |
| 912 } | 911 } |
| 913 } | 912 } |
| 914 | 913 |
| 915 | 914 |
| 916 void ClientSocket::EnsureInitialized( | 915 void ClientSocket::EnsureInitialized( |
| 917 EventHandlerImplementation* event_handler) { | 916 EventHandlerImplementation* event_handler) { |
| 918 ScopedLock lock(this); | 917 ScopedLock lock(this); |
| 919 if (completion_port_ == INVALID_HANDLE_VALUE) { | 918 if (completion_port_ == INVALID_HANDLE_VALUE) { |
| 920 ASSERT(event_handler_ == NULL); | 919 ASSERT(event_handler_ == NULL); |
| 921 event_handler_ = event_handler; | 920 event_handler_ = event_handler; |
| 922 CreateCompletionPort(event_handler_->completion_port()); | 921 CreateCompletionPort(event_handler_->completion_port()); |
| 923 } | 922 } |
| 924 } | 923 } |
| 925 | 924 |
| 926 | 925 |
| 927 bool ClientSocket::IsClosed() { | 926 bool ClientSocket::IsClosed() { |
| 928 return closed_; | 927 return connected_ && closed_; |
| 929 } | 928 } |
| 930 | 929 |
| 931 | 930 |
| 932 bool DatagramSocket::IssueSendTo(struct sockaddr* sa, socklen_t sa_len) { | 931 bool DatagramSocket::IssueSendTo(struct sockaddr* sa, socklen_t sa_len) { |
| 933 ScopedLock lock(this); | 932 ScopedLock lock(this); |
| 934 ASSERT(completion_port_ != INVALID_HANDLE_VALUE); | 933 ASSERT(completion_port_ != INVALID_HANDLE_VALUE); |
| 935 ASSERT(pending_write_ != NULL); | 934 ASSERT(pending_write_ != NULL); |
| 936 ASSERT(pending_write_->operation() == OverlappedBuffer::kSendTo); | 935 ASSERT(pending_write_->operation() == OverlappedBuffer::kSendTo); |
| 937 | 936 |
| 938 int rc = WSASendTo(socket(), | 937 int rc = WSASendTo(socket(), |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1190 void EventHandlerImplementation::HandleConnect( | 1189 void EventHandlerImplementation::HandleConnect( |
| 1191 ClientSocket* client_socket, | 1190 ClientSocket* client_socket, |
| 1192 int bytes, | 1191 int bytes, |
| 1193 OverlappedBuffer* buffer) { | 1192 OverlappedBuffer* buffer) { |
| 1194 if (bytes < 0) { | 1193 if (bytes < 0) { |
| 1195 HandleError(client_socket); | 1194 HandleError(client_socket); |
| 1196 OverlappedBuffer::DisposeBuffer(buffer); | 1195 OverlappedBuffer::DisposeBuffer(buffer); |
| 1197 } else { | 1196 } else { |
| 1198 client_socket->ConnectComplete(buffer); | 1197 client_socket->ConnectComplete(buffer); |
| 1199 } | 1198 } |
| 1199 client_socket->mark_connected(); |
| 1200 DeleteIfClosed(client_socket); |
| 1200 } | 1201 } |
| 1201 | 1202 |
| 1202 | 1203 |
| 1203 void EventHandlerImplementation::HandleTimeout() { | 1204 void EventHandlerImplementation::HandleTimeout() { |
| 1204 if (!timeout_queue_.HasTimeout()) return; | 1205 if (!timeout_queue_.HasTimeout()) return; |
| 1205 DartUtils::PostNull(timeout_queue_.CurrentPort()); | 1206 DartUtils::PostNull(timeout_queue_.CurrentPort()); |
| 1206 timeout_queue_.RemoveCurrent(); | 1207 timeout_queue_.RemoveCurrent(); |
| 1207 } | 1208 } |
| 1208 | 1209 |
| 1209 | 1210 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1362 | 1363 |
| 1363 | 1364 |
| 1364 void EventHandlerImplementation::Shutdown() { | 1365 void EventHandlerImplementation::Shutdown() { |
| 1365 SendData(kShutdownId, 0, 0); | 1366 SendData(kShutdownId, 0, 0); |
| 1366 } | 1367 } |
| 1367 | 1368 |
| 1368 } // namespace bin | 1369 } // namespace bin |
| 1369 } // namespace dart | 1370 } // namespace dart |
| 1370 | 1371 |
| 1371 #endif // defined(TARGET_OS_WINDOWS) | 1372 #endif // defined(TARGET_OS_WINDOWS) |
| OLD | NEW |