| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 void Handle::Lock() { | 152 void Handle::Lock() { |
| 153 EnterCriticalSection(&cs_); | 153 EnterCriticalSection(&cs_); |
| 154 } | 154 } |
| 155 | 155 |
| 156 | 156 |
| 157 void Handle::Unlock() { | 157 void Handle::Unlock() { |
| 158 LeaveCriticalSection(&cs_); | 158 LeaveCriticalSection(&cs_); |
| 159 } | 159 } |
| 160 | 160 |
| 161 | 161 |
| 162 bool Handle::DoCreateCompletionPort(HANDLE handle, HANDLE completion_port) { | 162 bool Handle::CreateCompletionPort(HANDLE completion_port) { |
| 163 completion_port_ = CreateIoCompletionPort(handle, | 163 completion_port_ = CreateIoCompletionPort(handle(), |
| 164 completion_port, | 164 completion_port, |
| 165 reinterpret_cast<ULONG_PTR>(this), | 165 reinterpret_cast<ULONG_PTR>(this), |
| 166 0); | 166 0); |
| 167 if (completion_port_ == NULL) { | 167 if (completion_port_ == NULL) { |
| 168 return false; | 168 return false; |
| 169 } | 169 } |
| 170 return true; | 170 return true; |
| 171 } | 171 } |
| 172 | 172 |
| 173 | 173 |
| 174 bool Handle::CreateCompletionPort(HANDLE completion_port) { | |
| 175 return DoCreateCompletionPort(handle_, completion_port_); | |
| 176 } | |
| 177 | |
| 178 | |
| 179 void Handle::Close() { | 174 void Handle::Close() { |
| 180 ScopedLock lock(this); | 175 ScopedLock lock(this); |
| 181 if (!IsClosing()) { | 176 if (!IsClosing()) { |
| 182 // Close the socket and set the closing state. This close method can be | 177 // Close the socket and set the closing state. This close method can be |
| 183 // called again if this socket has pending IO operations in flight. | 178 // called again if this socket has pending IO operations in flight. |
| 184 MarkClosing(); | 179 MarkClosing(); |
| 185 // Perform handle type specific closing. | 180 // Perform handle type specific closing. |
| 186 DoClose(); | 181 DoClose(); |
| 187 } | 182 } |
| 188 ASSERT(IsHandleClosed()); | 183 ASSERT(IsHandleClosed()); |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 | 425 |
| 431 if (pending_read_ != NULL) { | 426 if (pending_read_ != NULL) { |
| 432 CancelIoEx(handle(), pending_read_->GetCleanOverlapped()); | 427 CancelIoEx(handle(), pending_read_->GetCleanOverlapped()); |
| 433 // Don't dispose of the buffer, as it will still complete (with length 0). | 428 // Don't dispose of the buffer, as it will still complete (with length 0). |
| 434 } | 429 } |
| 435 | 430 |
| 436 DoClose(); | 431 DoClose(); |
| 437 } | 432 } |
| 438 | 433 |
| 439 | 434 |
| 440 bool SocketHandle::CreateCompletionPort(HANDLE completion_port) { | |
| 441 HANDLE handle = reinterpret_cast<HANDLE>(socket()); | |
| 442 return DoCreateCompletionPort(handle, completion_port); | |
| 443 } | |
| 444 | |
| 445 | |
| 446 void SocketHandle::HandleIssueError() { | 435 void SocketHandle::HandleIssueError() { |
| 447 int error = WSAGetLastError(); | 436 int error = WSAGetLastError(); |
| 448 if (error == WSAECONNRESET) { | 437 if (error == WSAECONNRESET) { |
| 449 HandleClosed(this); | 438 HandleClosed(this); |
| 450 } else { | 439 } else { |
| 451 HandleError(this); | 440 HandleError(this); |
| 452 } | 441 } |
| 453 WSASetLastError(error); | 442 WSASetLastError(error); |
| 454 } | 443 } |
| 455 | 444 |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 MarkClosedRead(); | 801 MarkClosedRead(); |
| 813 MarkClosedWrite(); | 802 MarkClosedWrite(); |
| 814 } | 803 } |
| 815 } | 804 } |
| 816 | 805 |
| 817 | 806 |
| 818 void ClientSocket::DoClose() { | 807 void ClientSocket::DoClose() { |
| 819 // Always do a shutdown before initiating a disconnect. | 808 // Always do a shutdown before initiating a disconnect. |
| 820 shutdown(socket(), SD_BOTH); | 809 shutdown(socket(), SD_BOTH); |
| 821 IssueDisconnect(); | 810 IssueDisconnect(); |
| 811 handle_ = INVALID_HANDLE_VALUE; |
| 822 } | 812 } |
| 823 | 813 |
| 824 | 814 |
| 825 bool ClientSocket::IssueRead() { | 815 bool ClientSocket::IssueRead() { |
| 826 ScopedLock lock(this); | 816 ScopedLock lock(this); |
| 827 ASSERT(completion_port_ != INVALID_HANDLE_VALUE); | 817 ASSERT(completion_port_ != INVALID_HANDLE_VALUE); |
| 828 ASSERT(pending_read_ == NULL); | 818 ASSERT(pending_read_ == NULL); |
| 829 | 819 |
| 830 // TODO(sgjesse): Use a MTU value here. Only the loopback adapter can | 820 // TODO(sgjesse): Use a MTU value here. Only the loopback adapter can |
| 831 // handle 64k datagrams. | 821 // handle 64k datagrams. |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1374 | 1364 |
| 1375 | 1365 |
| 1376 void EventHandlerImplementation::Shutdown() { | 1366 void EventHandlerImplementation::Shutdown() { |
| 1377 SendData(kShutdownId, 0, 0); | 1367 SendData(kShutdownId, 0, 0); |
| 1378 } | 1368 } |
| 1379 | 1369 |
| 1380 } // namespace bin | 1370 } // namespace bin |
| 1381 } // namespace dart | 1371 } // namespace dart |
| 1382 | 1372 |
| 1383 #endif // defined(TARGET_OS_WINDOWS) | 1373 #endif // defined(TARGET_OS_WINDOWS) |
| OLD | NEW |