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

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

Issue 171503009: Remove SocketData and now only pass the dart port to epoll. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | « runtime/bin/eventhandler_android.cc ('k') | runtime/bin/eventhandler_linux.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_LINUX_H_ 5 #ifndef BIN_EVENTHANDLER_LINUX_H_
6 #define BIN_EVENTHANDLER_LINUX_H_ 6 #define BIN_EVENTHANDLER_LINUX_H_
7 7
8 #if !defined(BIN_EVENTHANDLER_H_) 8 #if !defined(BIN_EVENTHANDLER_H_)
9 #error Do not include eventhandler_linux.h directly; use eventhandler.h instead. 9 #error Do not include eventhandler_linux.h directly; use eventhandler.h instead.
10 #endif 10 #endif
11 11
12 #include <unistd.h> 12 #include <unistd.h>
13 #include <sys/epoll.h> 13 #include <sys/epoll.h>
14 #include <sys/socket.h> 14 #include <sys/socket.h>
15 15
16 #include "platform/hashmap.h" 16 #include "platform/hashmap.h"
17 #include "platform/thread.h" 17 #include "platform/thread.h"
18 18
19 19
20 namespace dart { 20 namespace dart {
21 namespace bin { 21 namespace bin {
22 22
23 class InterruptMessage {
24 public:
25 intptr_t id;
26 Dart_Port dart_port;
27 int64_t data;
28 };
29
30
31 class SocketData {
32 public:
33 explicit SocketData(intptr_t fd)
34 : tracked_by_epoll_(false), fd_(fd), port_(0) {
35 ASSERT(fd_ != -1);
36 }
37
38 void ShutdownRead() {
39 shutdown(fd_, SHUT_RD);
40 }
41
42 void ShutdownWrite() {
43 shutdown(fd_, SHUT_WR);
44 }
45
46 void Close() {
47 port_ = 0;
48 close(fd_);
49 fd_ = -1;
50 }
51
52 void SetPort(Dart_Port port) {
53 ASSERT(fd_ != -1);
54 port_ = port;
55 }
56
57 intptr_t fd() { return fd_; }
58 Dart_Port port() { return port_; }
59 bool tracked_by_epoll() { return tracked_by_epoll_; }
60 void set_tracked_by_epoll(bool value) { tracked_by_epoll_ = value; }
61
62 private:
63 bool tracked_by_epoll_;
64 intptr_t fd_;
65 Dart_Port port_;
66 };
67
68
69 class EventHandlerImplementation { 23 class EventHandlerImplementation {
70 public: 24 public:
71 EventHandlerImplementation(); 25 EventHandlerImplementation();
72 ~EventHandlerImplementation(); 26 ~EventHandlerImplementation();
73 27
74 // Gets the socket data structure for a given file 28 void Notify(intptr_t id, Dart_Port dart_port, int64_t data);
75 // descriptor. Creates a new one if one is not found.
76 SocketData* GetSocketData(intptr_t fd, bool* is_new);
77 void SendData(intptr_t id, Dart_Port dart_port, int64_t data);
78 void Start(EventHandler* handler); 29 void Start(EventHandler* handler);
79 void Shutdown(); 30 void Shutdown();
80 31
81 private: 32 private:
82 void HandleEvents(struct epoll_event* events, int size); 33 void HandleEvents(struct epoll_event* events, int size);
83 static void Poll(uword args); 34 static void Poll(uword args);
84 void WakeupHandler(intptr_t id, Dart_Port dart_port, int64_t data);
85 void HandleInterruptFd();
86 void SetPort(intptr_t fd, Dart_Port dart_port, intptr_t mask); 35 void SetPort(intptr_t fd, Dart_Port dart_port, intptr_t mask);
87 intptr_t GetPollEvents(intptr_t events, SocketData* sd); 36 intptr_t GetPollEvents(intptr_t events);
88 static void* GetHashmapKeyFromFd(intptr_t fd);
89 static uint32_t GetHashmapHashFromFd(intptr_t fd);
90 37
91 HashMap socket_map_;
92 TimeoutQueue timeout_queue_; 38 TimeoutQueue timeout_queue_;
93 bool shutdown_; 39 bool shutdown_;
94 int interrupt_fds_[2];
95 int epoll_fd_; 40 int epoll_fd_;
96 int timer_fd_; 41 int timer_fd_;
42 Mutex timer_mutex_;
97 }; 43 };
98 44
99 } // namespace bin 45 } // namespace bin
100 } // namespace dart 46 } // namespace dart
101 47
102 #endif // BIN_EVENTHANDLER_LINUX_H_ 48 #endif // BIN_EVENTHANDLER_LINUX_H_
OLDNEW
« 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