| OLD | NEW |
| 1 // Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Fletch 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 #ifndef SRC_VM_EVENT_HANDLER_H_ | 5 #ifndef SRC_VM_EVENT_HANDLER_H_ |
| 6 #define SRC_VM_EVENT_HANDLER_H_ | 6 #define SRC_VM_EVENT_HANDLER_H_ |
| 7 | 7 |
| 8 #include "src/shared/globals.h" | 8 #include "src/shared/globals.h" |
| 9 #include "src/vm/hash_map.h" |
| 9 #include "src/vm/thread.h" | 10 #include "src/vm/thread.h" |
| 10 | 11 |
| 11 namespace fletch { | 12 namespace fletch { |
| 12 | 13 |
| 13 class Monitor; | 14 class Monitor; |
| 14 class Port; | 15 class Port; |
| 15 | 16 |
| 16 class EventHandler { | 17 class EventHandler { |
| 17 public: | 18 public: |
| 18 enum { | 19 enum { |
| 19 READ_EVENT = 1 << 0, | 20 READ_EVENT = 1 << 0, |
| 20 WRITE_EVENT = 1 << 1, | 21 WRITE_EVENT = 1 << 1, |
| 21 CLOSE_EVENT = 1 << 2, | 22 CLOSE_EVENT = 1 << 2, |
| 22 ERROR_EVENT = 1 << 3, | 23 ERROR_EVENT = 1 << 3, |
| 23 }; | 24 }; |
| 24 | 25 |
| 25 EventHandler(); | 26 EventHandler(); |
| 26 ~EventHandler(); | 27 ~EventHandler(); |
| 27 | 28 |
| 28 int GetEventHandler(); | 29 int GetEventHandler(); |
| 30 void ScheduleTimeout(int64 timeout, Port* port); |
| 29 | 31 |
| 30 Monitor* monitor() const { return monitor_; } | 32 Monitor* monitor() const { return monitor_; } |
| 31 | 33 |
| 32 int Create(); | 34 int Create(); |
| 33 void Run(); | 35 void Run(); |
| 34 | 36 |
| 35 private: | 37 private: |
| 36 Monitor* monitor_; | 38 Monitor* monitor_; |
| 37 int fd_; | 39 int fd_; |
| 38 ThreadIdentifier thread_; | 40 ThreadIdentifier thread_; |
| 39 | 41 |
| 42 HashMap<Port*, int64> timeouts_; |
| 43 int64 next_timeout_; |
| 44 |
| 40 int read_fd_; | 45 int read_fd_; |
| 41 int write_fd_; | 46 int write_fd_; |
| 42 | 47 |
| 43 void Send(Port* port, uword mask); | 48 void Send(Port* port, uword mask); |
| 44 }; | 49 }; |
| 45 | 50 |
| 46 } // namespace fletch | 51 } // namespace fletch |
| 47 | 52 |
| 48 #endif // SRC_VM_EVENT_HANDLER_H_ | 53 #endif // SRC_VM_EVENT_HANDLER_H_ |
| OLD | NEW |