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 #ifndef BIN_EVENTHANDLER_WIN_H_ | 5 #ifndef BIN_EVENTHANDLER_WIN_H_ |
6 #define BIN_EVENTHANDLER_WIN_H_ | 6 #define BIN_EVENTHANDLER_WIN_H_ |
7 | 7 |
8 #include <winsock2.h> | 8 #include <winsock2.h> |
9 #include <mswsock.h> | 9 #include <mswsock.h> |
10 | 10 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 ~ScopedLock() { | 132 ~ScopedLock() { |
133 handle_->Unlock(); | 133 handle_->Unlock(); |
134 } | 134 } |
135 | 135 |
136 private: | 136 private: |
137 Handle* handle_; | 137 Handle* handle_; |
138 }; | 138 }; |
139 | 139 |
140 virtual ~Handle(); | 140 virtual ~Handle(); |
141 | 141 |
| 142 // Socket interface exposing normal socket operations. |
| 143 int Available(); |
| 144 int Read(void* buffer, int num_bytes); |
| 145 int Write(const void* buffer, int num_bytes); |
| 146 |
142 // Internal interface used by the event handler. | 147 // Internal interface used by the event handler. |
143 virtual bool IssueRead(); | 148 virtual bool IssueRead(); |
144 virtual bool IssueWrite(); | 149 virtual bool IssueWrite(); |
145 bool HasPendingRead(); | 150 bool HasPendingRead(); |
146 bool HasPendingWrite(); | 151 bool HasPendingWrite(); |
147 void ReadComplete(IOBuffer* buffer); | 152 void ReadComplete(IOBuffer* buffer); |
148 void WriteComplete(IOBuffer* buffer); | 153 void WriteComplete(IOBuffer* buffer); |
149 | 154 |
150 virtual void EnsureInitialized( | 155 virtual void EnsureInitialized( |
151 EventHandlerImplementation* event_handler) = 0; | 156 EventHandlerImplementation* event_handler) = 0; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 IOBuffer* pending_write_; // IO buffer for pending write | 200 IOBuffer* pending_write_; // IO buffer for pending write |
196 }; | 201 }; |
197 | 202 |
198 | 203 |
199 class FileHandle : public Handle { | 204 class FileHandle : public Handle { |
200 public: | 205 public: |
201 explicit FileHandle(HANDLE handle) | 206 explicit FileHandle(HANDLE handle) |
202 : Handle(reinterpret_cast<HANDLE>(handle)) { type_ = kFile; } | 207 : Handle(reinterpret_cast<HANDLE>(handle)) { type_ = kFile; } |
203 FileHandle(HANDLE handle, Dart_Port port) | 208 FileHandle(HANDLE handle, Dart_Port port) |
204 : Handle(reinterpret_cast<HANDLE>(handle), port) { type_ = kFile; } | 209 : Handle(reinterpret_cast<HANDLE>(handle), port) { type_ = kFile; } |
| 210 |
| 211 virtual void EnsureInitialized(EventHandlerImplementation* event_handler); |
| 212 virtual bool IsClosed(); |
| 213 |
| 214 private: |
| 215 virtual void AfterClose(); |
205 }; | 216 }; |
206 | 217 |
207 | 218 |
208 class SocketHandle : public Handle { | 219 class SocketHandle : public Handle { |
209 public: | 220 public: |
210 SOCKET socket() { return reinterpret_cast<SOCKET>(handle_); } | 221 SOCKET socket() { return reinterpret_cast<SOCKET>(handle_); } |
211 | 222 |
212 protected: | 223 protected: |
213 explicit SocketHandle(SOCKET s) : Handle(reinterpret_cast<HANDLE>(s)) {} | 224 explicit SocketHandle(SOCKET s) : Handle(reinterpret_cast<HANDLE>(s)) {} |
214 SocketHandle(SOCKET s, Dart_Port port) | 225 SocketHandle(SOCKET s, Dart_Port port) |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 : SocketHandle(s, port), | 281 : SocketHandle(s, port), |
271 next_(NULL) { type_ = kClientSocket; } | 282 next_(NULL) { type_ = kClientSocket; } |
272 | 283 |
273 virtual ~ClientSocket() { | 284 virtual ~ClientSocket() { |
274 // Don't delete this object until all pending requests have been handled. | 285 // Don't delete this object until all pending requests have been handled. |
275 ASSERT(!HasPendingRead()); | 286 ASSERT(!HasPendingRead()); |
276 ASSERT(!HasPendingWrite()); | 287 ASSERT(!HasPendingWrite()); |
277 ASSERT(next_ == NULL); | 288 ASSERT(next_ == NULL); |
278 }; | 289 }; |
279 | 290 |
280 // Socket interface exposing normal socket operations. | |
281 int Available(); | |
282 int Read(void* buffer, int num_bytes); | |
283 int Write(const void* buffer, int num_bytes); | |
284 | |
285 // Internal interface used by the event handler. | 291 // Internal interface used by the event handler. |
286 virtual bool IssueRead(); | 292 virtual bool IssueRead(); |
287 virtual bool IssueWrite(); | 293 virtual bool IssueWrite(); |
288 | 294 |
289 virtual void EnsureInitialized( | 295 virtual void EnsureInitialized( |
290 EventHandlerImplementation* event_handler); | 296 EventHandlerImplementation* event_handler); |
291 virtual bool IsClosed(); | 297 virtual bool IsClosed(); |
292 | 298 |
293 ClientSocket* next() { return next_; } | 299 ClientSocket* next() { return next_; } |
294 void set_next(ClientSocket* next) { next_ = next; } | 300 void set_next(ClientSocket* next) { next_ = next; } |
(...skipping 29 matching lines...) Expand all Loading... |
324 private: | 330 private: |
325 ClientSocket* client_sockets_head_; | 331 ClientSocket* client_sockets_head_; |
326 | 332 |
327 int64_t timeout_; // Time for next timeout. | 333 int64_t timeout_; // Time for next timeout. |
328 Dart_Port timeout_port_; | 334 Dart_Port timeout_port_; |
329 HANDLE completion_port_; | 335 HANDLE completion_port_; |
330 }; | 336 }; |
331 | 337 |
332 | 338 |
333 #endif // BIN_EVENTHANDLER_WIN_H_ | 339 #endif // BIN_EVENTHANDLER_WIN_H_ |
OLD | NEW |