| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 <process.h> | 5 #include <process.h> |
| 6 #include <winsock2.h> | 6 #include <winsock2.h> |
| 7 #include <ws2tcpip.h> | 7 #include <ws2tcpip.h> |
| 8 #include <mswsock.h> | 8 #include <mswsock.h> |
| 9 | 9 |
| 10 #include "bin/builtin.h" | 10 #include "bin/builtin.h" |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 | 476 |
| 477 | 477 |
| 478 int Handle::Write(const void* buffer, int num_bytes) { | 478 int Handle::Write(const void* buffer, int num_bytes) { |
| 479 ScopedLock lock(this); | 479 ScopedLock lock(this); |
| 480 if (SupportsOverlappedIO()) { | 480 if (SupportsOverlappedIO()) { |
| 481 if (pending_write_ != NULL) return 0; | 481 if (pending_write_ != NULL) return 0; |
| 482 if (completion_port_ == INVALID_HANDLE_VALUE) return 0; | 482 if (completion_port_ == INVALID_HANDLE_VALUE) return 0; |
| 483 if (num_bytes > 4096) num_bytes = 4096; | 483 if (num_bytes > 4096) num_bytes = 4096; |
| 484 pending_write_ = IOBuffer::AllocateWriteBuffer(num_bytes); | 484 pending_write_ = IOBuffer::AllocateWriteBuffer(num_bytes); |
| 485 pending_write_->Write(buffer, num_bytes); | 485 pending_write_->Write(buffer, num_bytes); |
| 486 IssueWrite(); | 486 if (!IssueWrite()) return -1; |
| 487 return num_bytes; | 487 return num_bytes; |
| 488 } else { | 488 } else { |
| 489 DWORD bytes_written; | 489 DWORD bytes_written = -1; |
| 490 BOOL ok = WriteFile(handle_, | 490 BOOL ok = WriteFile(handle_, |
| 491 buffer, | 491 buffer, |
| 492 num_bytes, | 492 num_bytes, |
| 493 &bytes_written, | 493 &bytes_written, |
| 494 NULL); | 494 NULL); |
| 495 if (!ok) { | 495 if (!ok) { |
| 496 if (GetLastError() != ERROR_BROKEN_PIPE) { | 496 if (GetLastError() != ERROR_BROKEN_PIPE) { |
| 497 fprintf(stderr, "WriteFile failed: %d\n", GetLastError()); | 497 fprintf(stderr, "WriteFile failed: %d\n", GetLastError()); |
| 498 } | 498 } |
| 499 event_handler_->HandleClosed(this); | 499 event_handler_->HandleClosed(this); |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 _beginthreadex(NULL, 32 * 1024, EventHandlerThread, this, 0, &tid); | 882 _beginthreadex(NULL, 32 * 1024, EventHandlerThread, this, 0, &tid); |
| 883 if (thread_handle == -1) { | 883 if (thread_handle == -1) { |
| 884 FATAL("Failed to start event handler thread"); | 884 FATAL("Failed to start event handler thread"); |
| 885 } | 885 } |
| 886 | 886 |
| 887 // Initialize Winsock32 | 887 // Initialize Winsock32 |
| 888 if (!Socket::Initialize()) { | 888 if (!Socket::Initialize()) { |
| 889 FATAL("Failed to initialized Windows sockets"); | 889 FATAL("Failed to initialized Windows sockets"); |
| 890 } | 890 } |
| 891 } | 891 } |
| OLD | NEW |