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

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

Issue 198743002: Make the event-handler handle backpreasure. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Doc fix Created 6 years, 9 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 | « runtime/bin/eventhandler.h ('k') | 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.
(...skipping 13 matching lines...) Expand all
24 public: 24 public:
25 intptr_t id; 25 intptr_t id;
26 Dart_Port dart_port; 26 Dart_Port dart_port;
27 int64_t data; 27 int64_t data;
28 }; 28 };
29 29
30 30
31 class SocketData { 31 class SocketData {
32 public: 32 public:
33 explicit SocketData(intptr_t fd) 33 explicit SocketData(intptr_t fd)
34 : tracked_by_epoll_(false), fd_(fd), port_(0), mask_(0) { 34 : fd_(fd), port_(0), mask_(0), tokens_(8) {
35 ASSERT(fd_ != -1); 35 ASSERT(fd_ != -1);
36 } 36 }
37 37
38 void ShutdownRead() { 38 intptr_t GetPollEvents();
39 shutdown(fd_, SHUT_RD);
40 }
41
42 void ShutdownWrite() {
43 shutdown(fd_, SHUT_WR);
44 }
45 39
46 void Close() { 40 void Close() {
47 port_ = 0; 41 port_ = 0;
48 mask_ = 0; 42 mask_ = 0;
49 close(fd_); 43 close(fd_);
50 fd_ = -1; 44 fd_ = -1;
51 } 45 }
52 46
53 bool IsListeningSocket() { return (mask_ & (1 << kListeningSocket)) != 0; }
54 bool IsPipe() { return (mask_ & (1 << kPipe)) != 0; }
55
56 void SetPortAndMask(Dart_Port port, intptr_t mask) { 47 void SetPortAndMask(Dart_Port port, intptr_t mask) {
57 ASSERT(fd_ != -1); 48 ASSERT(fd_ != -1);
58 port_ = port; 49 port_ = port;
59 mask_ = mask; 50 mask_ = mask;
60 } 51 }
61 52
62 intptr_t fd() { return fd_; } 53 intptr_t fd() { return fd_; }
63 Dart_Port port() { return port_; } 54 Dart_Port port() { return port_; }
64 intptr_t mask() { return mask_; } 55
65 bool tracked_by_epoll() { return tracked_by_epoll_; } 56 // Returns true if the last token was taken.
66 void set_tracked_by_epoll(bool value) { tracked_by_epoll_ = value; } 57 bool TakeToken() {
58 ASSERT(tokens_ > 0);
59 tokens_--;
60 return tokens_ == 0;
61 }
62
63 // Returns true if the tokens was 0 before adding.
64 bool ReturnToken() {
65 ASSERT(tokens_ >= 0);
66 tokens_++;
67 return tokens_ == 1;
68 }
67 69
68 private: 70 private:
69 bool tracked_by_epoll_;
70 intptr_t fd_; 71 intptr_t fd_;
71 Dart_Port port_; 72 Dart_Port port_;
72 intptr_t mask_; 73 intptr_t mask_;
74 int tokens_;
73 }; 75 };
74 76
75 77
76 class EventHandlerImplementation { 78 class EventHandlerImplementation {
77 public: 79 public:
78 EventHandlerImplementation(); 80 EventHandlerImplementation();
79 ~EventHandlerImplementation(); 81 ~EventHandlerImplementation();
80 82
81 // Gets the socket data structure for a given file 83 // Gets the socket data structure for a given file
82 // descriptor. Creates a new one if one is not found. 84 // descriptor. Creates a new one if one is not found.
83 SocketData* GetSocketData(intptr_t fd, bool* is_new); 85 SocketData* GetSocketData(intptr_t fd);
84 void Notify(intptr_t id, Dart_Port dart_port, intptr_t data); 86 void SendData(intptr_t id, Dart_Port dart_port, intptr_t data);
85 void Start(EventHandler* handler); 87 void Start(EventHandler* handler);
86 void Shutdown(); 88 void Shutdown();
87 89
88 private: 90 private:
89 int64_t GetTimeout(); 91 int64_t GetTimeout();
90 void HandleEvents(struct epoll_event* events, int size); 92 void HandleEvents(struct epoll_event* events, int size);
91 void HandleTimeout(); 93 void HandleTimeout();
92 static void Poll(uword args); 94 static void Poll(uword args);
93 void WakeupHandler(intptr_t id, Dart_Port dart_port, int64_t data); 95 void WakeupHandler(intptr_t id, Dart_Port dart_port, int64_t data);
94 void HandleInterruptFd(); 96 void HandleInterruptFd();
95 void SetPort(intptr_t fd, Dart_Port dart_port, intptr_t mask); 97 void SetPort(intptr_t fd, Dart_Port dart_port, intptr_t mask);
96 intptr_t GetPollEvents(intptr_t events, SocketData* sd); 98 intptr_t GetPollEvents(intptr_t events, SocketData* sd);
97 static void* GetHashmapKeyFromFd(intptr_t fd); 99 static void* GetHashmapKeyFromFd(intptr_t fd);
98 static uint32_t GetHashmapHashFromFd(intptr_t fd); 100 static uint32_t GetHashmapHashFromFd(intptr_t fd);
99 101
100 HashMap socket_map_; 102 HashMap socket_map_;
101 TimeoutQueue timeout_queue_; 103 TimeoutQueue timeout_queue_;
102 bool shutdown_; 104 bool shutdown_;
103 int interrupt_fds_[2]; 105 int interrupt_fds_[2];
104 int epoll_fd_; 106 int epoll_fd_;
105 }; 107 };
106 108
107 } // namespace bin 109 } // namespace bin
108 } // namespace dart 110 } // namespace dart
109 111
110 #endif // BIN_EVENTHANDLER_ANDROID_H_ 112 #endif // BIN_EVENTHANDLER_ANDROID_H_
OLDNEW
« no previous file with comments | « runtime/bin/eventhandler.h ('k') | runtime/bin/eventhandler_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698