Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: dart/runtime/bin/eventhandler_android.h

Issue 905733002: Extract common Mask/Dart_Port settings of linux event handler implementation to eventhandler.h (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « dart/runtime/bin/eventhandler.h ('k') | dart/runtime/bin/eventhandler_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef BIN_EVENTHANDLER_ANDROID_H_ 5 #ifndef BIN_EVENTHANDLER_ANDROID_H_
6 #define BIN_EVENTHANDLER_ANDROID_H_ 6 #define BIN_EVENTHANDLER_ANDROID_H_
7 7
8 #if !defined(BIN_EVENTHANDLER_H_) 8 #if !defined(BIN_EVENTHANDLER_H_)
9 #error Do not include eventhandler_android.h directly; 9 #error Do not include eventhandler_android.h directly;
10 #error use eventhandler.h instead. 10 #error use eventhandler.h instead.
11 #endif 11 #endif
12 12
13 #include <errno.h> 13 #include <errno.h>
14 #include <sys/epoll.h> 14 #include <sys/epoll.h>
15 #include <sys/socket.h> 15 #include <sys/socket.h>
16 #include <unistd.h> 16 #include <unistd.h>
17 17
18 #include "platform/hashmap.h" 18 #include "platform/hashmap.h"
19 #include "platform/signal_blocker.h" 19 #include "platform/signal_blocker.h"
20 20
21 21
22 namespace dart { 22 namespace dart {
23 namespace bin { 23 namespace bin {
24 24
25 class SocketData { 25 class DescriptorInfo : public DescriptorInfoBase {
26 public: 26 public:
27 explicit SocketData(intptr_t fd, bool listening_socket) 27 explicit DescriptorInfo(intptr_t fd) : DescriptorInfoBase(fd) { }
28 : fd_(fd), port_(0), mask_(0), tokens_(16), 28
29 listening_socket_(listening_socket) { 29 virtual ~DescriptorInfo() { }
30 ASSERT(fd_ != -1);
31 }
32 30
33 intptr_t GetPollEvents(); 31 intptr_t GetPollEvents();
34 32
35 void Close() { 33 virtual void Close() {
36 port_ = 0;
37 mask_ = 0;
38 VOID_TEMP_FAILURE_RETRY(close(fd_)); 34 VOID_TEMP_FAILURE_RETRY(close(fd_));
39 fd_ = -1; 35 fd_ = -1;
40 } 36 }
41
42 void SetPortAndMask(Dart_Port port, intptr_t mask) {
43 ASSERT(fd_ != -1);
44 port_ = port;
45 mask_ = mask;
46 }
47
48 intptr_t fd() { return fd_; }
49 Dart_Port port() { return port_; }
50
51 bool IsListeningSocket() { return listening_socket_; }
52
53 // Returns true if the last token was taken.
54 bool TakeToken() {
55 ASSERT(tokens_ > 0);
56 tokens_--;
57 return tokens_ == 0;
58 }
59
60 // Returns true if the tokens was 0 before adding.
61 bool ReturnToken() {
62 ASSERT(tokens_ >= 0);
63 tokens_++;
64 return tokens_ == 1;
65 }
66
67 private:
68 intptr_t fd_;
69 Dart_Port port_;
70 intptr_t mask_;
71 int tokens_;
72 bool listening_socket_;
73 }; 37 };
74 38
75 39
40 class DescriptorInfoSingle
41 : public DescriptorInfoSingleMixin<DescriptorInfo> {
42 public:
43 explicit DescriptorInfoSingle(intptr_t fd)
44 : DescriptorInfoSingleMixin(fd) {}
45 virtual ~DescriptorInfoSingle() {}
46 };
47
48
49 class DescriptorInfoMultiple
50 : public DescriptorInfoMultipleMixin<DescriptorInfo> {
51 public:
52 explicit DescriptorInfoMultiple(intptr_t fd)
53 : DescriptorInfoMultipleMixin(fd) {}
54 virtual ~DescriptorInfoMultiple() {}
55 };
56
57
76 class EventHandlerImplementation { 58 class EventHandlerImplementation {
77 public: 59 public:
78 EventHandlerImplementation(); 60 EventHandlerImplementation();
79 ~EventHandlerImplementation(); 61 ~EventHandlerImplementation();
80 62
63 void UpdateEpollInstance(intptr_t old_mask, DescriptorInfo *di);
64
81 // Gets the socket data structure for a given file 65 // Gets the socket data structure for a given file
82 // descriptor. Creates a new one if one is not found. 66 // descriptor. Creates a new one if one is not found.
83 SocketData* GetSocketData(intptr_t fd, bool is_listening); 67 DescriptorInfo* GetDescriptorInfo(intptr_t fd, bool is_listening);
84 void SendData(intptr_t id, Dart_Port dart_port, intptr_t data); 68 void SendData(intptr_t id, Dart_Port dart_port, int64_t data);
85 void Start(EventHandler* handler); 69 void Start(EventHandler* handler);
86 void Shutdown(); 70 void Shutdown();
87 71
88 private: 72 private:
89 int64_t GetTimeout(); 73 int64_t GetTimeout();
90 void HandleEvents(struct epoll_event* events, int size); 74 void HandleEvents(struct epoll_event* events, int size);
91 void HandleTimeout(); 75 void HandleTimeout();
92 static void Poll(uword args); 76 static void Poll(uword args);
93 void WakeupHandler(intptr_t id, Dart_Port dart_port, int64_t data); 77 void WakeupHandler(intptr_t id, Dart_Port dart_port, int64_t data);
94 void HandleInterruptFd(); 78 void HandleInterruptFd();
95 void SetPort(intptr_t fd, Dart_Port dart_port, intptr_t mask); 79 void SetPort(intptr_t fd, Dart_Port dart_port, intptr_t mask);
96 intptr_t GetPollEvents(intptr_t events, SocketData* sd); 80 intptr_t GetPollEvents(intptr_t events, DescriptorInfo* di);
97 static void* GetHashmapKeyFromFd(intptr_t fd); 81 static void* GetHashmapKeyFromFd(intptr_t fd);
98 static uint32_t GetHashmapHashFromFd(intptr_t fd); 82 static uint32_t GetHashmapHashFromFd(intptr_t fd);
99 83
100 HashMap socket_map_; 84 HashMap socket_map_;
101 TimeoutQueue timeout_queue_; 85 TimeoutQueue timeout_queue_;
102 bool shutdown_; 86 bool shutdown_;
103 int interrupt_fds_[2]; 87 int interrupt_fds_[2];
104 int epoll_fd_; 88 int epoll_fd_;
105 }; 89 };
106 90
107 } // namespace bin 91 } // namespace bin
108 } // namespace dart 92 } // namespace dart
109 93
110 #endif // BIN_EVENTHANDLER_ANDROID_H_ 94 #endif // BIN_EVENTHANDLER_ANDROID_H_
OLDNEW
« no previous file with comments | « dart/runtime/bin/eventhandler.h ('k') | dart/runtime/bin/eventhandler_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698