Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 |
| 12 #include <ws2tcpip.h> // NOLINT | 12 #include <ws2tcpip.h> // NOLINT |
| 13 #include <mswsock.h> // NOLINT | 13 #include <mswsock.h> // NOLINT |
| 14 | 14 |
| 15 #include "bin/builtin.h" | 15 #include "bin/builtin.h" |
| 16 #include "bin/dartutils.h" | 16 #include "bin/dartutils.h" |
| 17 #include "bin/log.h" | 17 #include "bin/log.h" |
| 18 #include "bin/socket.h" | 18 #include "bin/socket.h" |
| 19 #include "bin/utils.h" | 19 #include "bin/utils.h" |
| 20 #include "platform/thread.h" | 20 #include "platform/thread.h" |
| 21 | 21 |
| 22 | 22 |
| 23 #define BUFFER_SIZE 32 * 1024 | |
|
Mads Ager (google)
2013/03/19 15:11:20
Please use a constant as below.
static const int
Søren Gjesse
2013/03/19 15:26:48
Done.
| |
| 24 | |
| 23 static const int kInfinityTimeout = -1; | 25 static const int kInfinityTimeout = -1; |
| 24 static const int kTimeoutId = -1; | 26 static const int kTimeoutId = -1; |
| 25 static const int kShutdownId = -2; | 27 static const int kShutdownId = -2; |
| 26 | 28 |
| 27 IOBuffer* IOBuffer::AllocateBuffer(int buffer_size, Operation operation) { | 29 IOBuffer* IOBuffer::AllocateBuffer(int buffer_size, Operation operation) { |
| 28 IOBuffer* buffer = new(buffer_size) IOBuffer(buffer_size, operation); | 30 IOBuffer* buffer = new(buffer_size) IOBuffer(buffer_size, operation); |
| 29 return buffer; | 31 return buffer; |
| 30 } | 32 } |
| 31 | 33 |
| 32 | 34 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 if (!ok) { | 229 if (!ok) { |
| 228 FATAL("PostQueuedCompletionStatus failed"); | 230 FATAL("PostQueuedCompletionStatus failed"); |
| 229 } | 231 } |
| 230 } | 232 } |
| 231 | 233 |
| 232 | 234 |
| 233 bool Handle::IssueRead() { | 235 bool Handle::IssueRead() { |
| 234 ScopedLock lock(this); | 236 ScopedLock lock(this); |
| 235 ASSERT(type_ != kListenSocket); | 237 ASSERT(type_ != kListenSocket); |
| 236 ASSERT(pending_read_ == NULL); | 238 ASSERT(pending_read_ == NULL); |
| 237 IOBuffer* buffer = IOBuffer::AllocateReadBuffer(1024); | 239 IOBuffer* buffer = IOBuffer::AllocateReadBuffer(BUFFER_SIZE); |
| 238 if (SupportsOverlappedIO()) { | 240 if (SupportsOverlappedIO()) { |
| 239 ASSERT(completion_port_ != INVALID_HANDLE_VALUE); | 241 ASSERT(completion_port_ != INVALID_HANDLE_VALUE); |
| 240 | 242 |
| 241 BOOL ok = ReadFile(handle_, | 243 BOOL ok = ReadFile(handle_, |
| 242 buffer->GetBufferStart(), | 244 buffer->GetBufferStart(), |
| 243 buffer->GetBufferSize(), | 245 buffer->GetBufferSize(), |
| 244 NULL, | 246 NULL, |
| 245 buffer->GetCleanOverlapped()); | 247 buffer->GetCleanOverlapped()); |
| 246 if (ok || GetLastError() == ERROR_IO_PENDING) { | 248 if (ok || GetLastError() == ERROR_IO_PENDING) { |
| 247 // Completing asynchronously. | 249 // Completing asynchronously. |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 } | 486 } |
| 485 return num_bytes; | 487 return num_bytes; |
| 486 } | 488 } |
| 487 | 489 |
| 488 | 490 |
| 489 int Handle::Write(const void* buffer, int num_bytes) { | 491 int Handle::Write(const void* buffer, int num_bytes) { |
| 490 ScopedLock lock(this); | 492 ScopedLock lock(this); |
| 491 if (SupportsOverlappedIO()) { | 493 if (SupportsOverlappedIO()) { |
| 492 if (pending_write_ != NULL) return 0; | 494 if (pending_write_ != NULL) return 0; |
| 493 if (completion_port_ == INVALID_HANDLE_VALUE) return 0; | 495 if (completion_port_ == INVALID_HANDLE_VALUE) return 0; |
| 494 if (num_bytes > 4096) num_bytes = 4096; | 496 if (num_bytes > BUFFER_SIZE) num_bytes = BUFFER_SIZE; |
| 495 pending_write_ = IOBuffer::AllocateWriteBuffer(num_bytes); | 497 pending_write_ = IOBuffer::AllocateWriteBuffer(num_bytes); |
| 496 pending_write_->Write(buffer, num_bytes); | 498 pending_write_->Write(buffer, num_bytes); |
| 497 if (!IssueWrite()) return -1; | 499 if (!IssueWrite()) return -1; |
| 498 return num_bytes; | 500 return num_bytes; |
| 499 } else { | 501 } else { |
| 500 DWORD bytes_written = -1; | 502 DWORD bytes_written = -1; |
| 501 BOOL ok = WriteFile(handle_, | 503 BOOL ok = WriteFile(handle_, |
| 502 buffer, | 504 buffer, |
| 503 num_bytes, | 505 num_bytes, |
| 504 &bytes_written, | 506 &bytes_written, |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 983 FATAL("Failed to initialized Windows sockets"); | 985 FATAL("Failed to initialized Windows sockets"); |
| 984 } | 986 } |
| 985 } | 987 } |
| 986 | 988 |
| 987 | 989 |
| 988 void EventHandlerImplementation::Shutdown() { | 990 void EventHandlerImplementation::Shutdown() { |
| 989 SendData(kShutdownId, 0, 0); | 991 SendData(kShutdownId, 0, 0); |
| 990 } | 992 } |
| 991 | 993 |
| 992 #endif // defined(TARGET_OS_WINDOWS) | 994 #endif // defined(TARGET_OS_WINDOWS) |
| OLD | NEW |