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

Unified Diff: runtime/bin/eventhandler_linux.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/eventhandler_android.cc ('k') | runtime/bin/eventhandler_linux.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/eventhandler_linux.h
diff --git a/runtime/bin/eventhandler_linux.h b/runtime/bin/eventhandler_linux.h
index f5386c34fbca8a1808a12ae8e5ace1899759f223..9341cd11f3ec30d9c7c5b13b1b4b60c33d764499 100644
--- a/runtime/bin/eventhandler_linux.h
+++ b/runtime/bin/eventhandler_linux.h
@@ -14,32 +14,93 @@
#include <sys/socket.h>
#include "platform/hashmap.h"
-#include "platform/thread.h"
namespace dart {
namespace bin {
+class InterruptMessage {
+ public:
+ intptr_t id;
+ Dart_Port dart_port;
+ int64_t data;
+};
+
+
+class SocketData {
+ public:
+ explicit SocketData(intptr_t fd) : fd_(fd), port_(0), mask_(0), tokens_(8) {
+ ASSERT(fd_ != -1);
+ }
+
+ intptr_t GetPollEvents();
+
+ void Close() {
+ port_ = 0;
+ mask_ = 0;
+ close(fd_);
+ fd_ = -1;
+ }
+
+ void SetPortAndMask(Dart_Port port, intptr_t mask) {
+ ASSERT(fd_ != -1);
+ port_ = port;
+ mask_ = mask;
+ }
+
+ intptr_t fd() { return fd_; }
+ Dart_Port port() { return port_; }
+
+ // Returns true if the last token was taken.
+ bool TakeToken() {
+ ASSERT(tokens_ > 0);
+ tokens_--;
+ return tokens_ == 0;
+ }
+
+ // Returns true if the tokens was 0 before adding.
+ bool ReturnToken() {
+ ASSERT(tokens_ >= 0);
+ tokens_++;
+ return tokens_ == 1;
+ }
+
+ private:
+ intptr_t fd_;
+ Dart_Port port_;
+ intptr_t mask_;
+ int tokens_;
+};
+
+
class EventHandlerImplementation {
public:
EventHandlerImplementation();
~EventHandlerImplementation();
- void Notify(intptr_t id, Dart_Port dart_port, int64_t data);
+ // Gets the socket data structure for a given file
+ // descriptor. Creates a new one if one is not found.
+ SocketData* GetSocketData(intptr_t fd);
+ void SendData(intptr_t id, Dart_Port dart_port, int64_t data);
void Start(EventHandler* handler);
void Shutdown();
private:
void HandleEvents(struct epoll_event* events, int size);
static void Poll(uword args);
+ void WakeupHandler(intptr_t id, Dart_Port dart_port, int64_t data);
+ void HandleInterruptFd();
void SetPort(intptr_t fd, Dart_Port dart_port, intptr_t mask);
- intptr_t GetPollEvents(intptr_t events);
+ intptr_t GetPollEvents(intptr_t events, SocketData* sd);
+ static void* GetHashmapKeyFromFd(intptr_t fd);
+ static uint32_t GetHashmapHashFromFd(intptr_t fd);
+ HashMap socket_map_;
TimeoutQueue timeout_queue_;
bool shutdown_;
+ int interrupt_fds_[2];
int epoll_fd_;
int timer_fd_;
- Mutex timer_mutex_;
};
} // namespace bin
« no previous file with comments | « runtime/bin/eventhandler_android.cc ('k') | runtime/bin/eventhandler_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698