| 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 "bin/eventhandler.h" | 5 #include "bin/eventhandler.h" |
| 6 | 6 |
| 7 #include <process.h> | 7 #include <process.h> |
| 8 #include <winsock2.h> | 8 #include <winsock2.h> |
| 9 #include <ws2tcpip.h> | 9 #include <ws2tcpip.h> |
| 10 #include <mswsock.h> | 10 #include <mswsock.h> |
| 11 | 11 |
| 12 #include "bin/builtin.h" | 12 #include "bin/builtin.h" |
| 13 #include "bin/dartutils.h" | 13 #include "bin/dartutils.h" |
| 14 #include "bin/log.h" | 14 #include "bin/log.h" |
| 15 #include "bin/socket.h" | 15 #include "bin/socket.h" |
| 16 #include "bin/utils.h" |
| 16 #include "platform/thread.h" | 17 #include "platform/thread.h" |
| 17 | 18 |
| 18 | 19 |
| 19 static const int kInfinityTimeout = -1; | 20 static const int kInfinityTimeout = -1; |
| 20 static const int kTimeoutId = -1; | 21 static const int kTimeoutId = -1; |
| 21 static const int kShutdownId = -2; | 22 static const int kShutdownId = -2; |
| 22 | 23 |
| 23 | 24 |
| 24 int64_t GetCurrentTimeMilliseconds() { | |
| 25 static const int64_t kTimeEpoc = 116444736000000000LL; | |
| 26 | |
| 27 // Although win32 uses 64-bit integers for representing timestamps, | |
| 28 // these are packed into a FILETIME structure. The FILETIME structure | |
| 29 // is just a struct representing a 64-bit integer. The TimeStamp union | |
| 30 // allows access to both a FILETIME and an integer representation of | |
| 31 // the timestamp. | |
| 32 union TimeStamp { | |
| 33 FILETIME ft_; | |
| 34 int64_t t_; | |
| 35 }; | |
| 36 TimeStamp time; | |
| 37 GetSystemTimeAsFileTime(&time.ft_); | |
| 38 return (time.t_ - kTimeEpoc) / 10000; | |
| 39 } | |
| 40 | |
| 41 IOBuffer* IOBuffer::AllocateBuffer(int buffer_size, Operation operation) { | 25 IOBuffer* IOBuffer::AllocateBuffer(int buffer_size, Operation operation) { |
| 42 IOBuffer* buffer = new(buffer_size) IOBuffer(buffer_size, operation); | 26 IOBuffer* buffer = new(buffer_size) IOBuffer(buffer_size, operation); |
| 43 return buffer; | 27 return buffer; |
| 44 } | 28 } |
| 45 | 29 |
| 46 | 30 |
| 47 IOBuffer* IOBuffer::AllocateAcceptBuffer(int buffer_size) { | 31 IOBuffer* IOBuffer::AllocateAcceptBuffer(int buffer_size) { |
| 48 IOBuffer* buffer = AllocateBuffer(buffer_size, kAccept); | 32 IOBuffer* buffer = AllocateBuffer(buffer_size, kAccept); |
| 49 return buffer; | 33 return buffer; |
| 50 } | 34 } |
| (...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 timeout_ = kInfinityTimeout; | 835 timeout_ = kInfinityTimeout; |
| 852 timeout_port_ = 0; | 836 timeout_port_ = 0; |
| 853 shutdown_ = false; | 837 shutdown_ = false; |
| 854 } | 838 } |
| 855 | 839 |
| 856 | 840 |
| 857 DWORD EventHandlerImplementation::GetTimeout() { | 841 DWORD EventHandlerImplementation::GetTimeout() { |
| 858 if (timeout_ == kInfinityTimeout) { | 842 if (timeout_ == kInfinityTimeout) { |
| 859 return kInfinityTimeout; | 843 return kInfinityTimeout; |
| 860 } | 844 } |
| 861 intptr_t millis = timeout_ - GetCurrentTimeMilliseconds(); | 845 intptr_t millis = timeout_ - TimerUtils::GetCurrentTimeMilliseconds(); |
| 862 return (millis < 0) ? 0 : millis; | 846 return (millis < 0) ? 0 : millis; |
| 863 } | 847 } |
| 864 | 848 |
| 865 | 849 |
| 866 void EventHandlerImplementation::SendData(intptr_t id, | 850 void EventHandlerImplementation::SendData(intptr_t id, |
| 867 Dart_Port dart_port, | 851 Dart_Port dart_port, |
| 868 int64_t data) { | 852 int64_t data) { |
| 869 InterruptMessage* msg = new InterruptMessage; | 853 InterruptMessage* msg = new InterruptMessage; |
| 870 msg->id = id; | 854 msg->id = id; |
| 871 msg->dart_port = dart_port; | 855 msg->dart_port = dart_port; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 // Initialize Winsock32 | 924 // Initialize Winsock32 |
| 941 if (!Socket::Initialize()) { | 925 if (!Socket::Initialize()) { |
| 942 FATAL("Failed to initialized Windows sockets"); | 926 FATAL("Failed to initialized Windows sockets"); |
| 943 } | 927 } |
| 944 } | 928 } |
| 945 | 929 |
| 946 | 930 |
| 947 void EventHandlerImplementation::Shutdown() { | 931 void EventHandlerImplementation::Shutdown() { |
| 948 SendData(kShutdownId, 0, 0); | 932 SendData(kShutdownId, 0, 0); |
| 949 } | 933 } |
| OLD | NEW |