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

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

Issue 8437090: Change the handling of closing sockets (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Another fix to SocketCloseTest Created 9 years, 1 month 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 #include <unistd.h>
9 #include <sys/socket.h>
10
8 11
9 class InterruptMessage { 12 class InterruptMessage {
10 public: 13 public:
11 intptr_t id; 14 intptr_t id;
12 Dart_Port dart_port; 15 Dart_Port dart_port;
13 int64_t data; 16 int64_t data;
14 }; 17 };
15 18
16 19
20 enum PortDataFlags {
21 kClosedRead = 0,
22 kClosedWrite = 1,
23 };
24
25
17 class SocketData { 26 class SocketData {
18 public: 27 public:
19 void FillPollEvents(struct pollfd* pollfds); 28 intptr_t GetPollEvents();
20 bool IsListeningSocket() { return (_mask & (1 << kListeningSocket)) != 0; } 29 void Unregister() {
30 port_ = 0;
31 mask_ = 0;
32 }
33 void ShutdownRead() {
Mads Ager (google) 2011/11/04 10:19:49 Add a blank line between multi-line methods?
Søren Gjesse 2011/11/04 12:15:11 Done.
34 shutdown(fd_, SHUT_RD);
35 MarkClosedRead();
36 }
37 void ShutdownWrite() {
38 shutdown(fd_, SHUT_WR);
39 MarkClosedWrite();
40 }
41 void Close() {
42 Unregister();
43 flags_ = 0;
44 close(fd_);
45 fd_ = 0;
46 }
21 47
22 Dart_Port port() { return _port; } 48 bool IsListeningSocket() { return (mask_ & (1 << kListeningSocket)) != 0; }
23 void set_port(Dart_Port port) { _port = port; } 49 bool IsClosedRead() { return (flags_ & (1 << kClosedRead)) != 0; }
24 intptr_t mask() { return _mask; } 50 bool IsClosedWrite() { return (flags_ & (1 << kClosedWrite)) != 0; }
25 void set_mask(intptr_t mask) { _mask = mask; } 51
52 void MarkClosedRead() { flags_ |= (1 << kClosedRead); }
53 void MarkClosedWrite() { flags_ |= (1 << kClosedWrite); }
54
55 bool HasPollEvents() { return mask_ != 0; }
56
57 void SetPortAndMask(Dart_Port port, intptr_t mask) {
58 port_ = port;
59 mask_ = mask;
60 }
61 intptr_t fd() { return fd_; }
62 void set_fd(intptr_t fd) { fd_ = fd; }
63 Dart_Port port() { return port_; }
64 intptr_t mask() { return mask_; }
26 65
27 private: 66 private:
28 Dart_Port _port; 67 intptr_t fd_;
29 intptr_t _mask; 68 Dart_Port port_;
69 intptr_t mask_;
70 intptr_t flags_;
30 }; 71 };
31 72
32 73
33 class EventHandlerImplementation { 74 class EventHandlerImplementation {
34 public: 75 public:
35 EventHandlerImplementation(); 76 EventHandlerImplementation();
36 ~EventHandlerImplementation(); 77 ~EventHandlerImplementation();
37 78
38 SocketData* GetSocketData(intptr_t fd); 79 SocketData* GetSocketData(intptr_t fd);
39 void SendData(intptr_t id, Dart_Port dart_port, intptr_t data); 80 void SendData(intptr_t id, Dart_Port dart_port, intptr_t data);
40 void StartEventHandler(); 81 void StartEventHandler();
41 82
42 private: 83 private:
43 intptr_t GetTimeout(); 84 intptr_t GetTimeout();
44 bool GetInterruptMessage(InterruptMessage* msg); 85 bool GetInterruptMessage(InterruptMessage* msg);
45 struct pollfd* GetPollFds(intptr_t* size); 86 struct pollfd* GetPollFds(intptr_t* size);
46 void RegisterFdWakeup(intptr_t id, Dart_Port dart_port, intptr_t data);
47 void UnregisterFdWakeup(intptr_t id);
48 void CloseFd(intptr_t id);
49 void UnregisterFd(intptr_t id);
50 void HandleEvents(struct pollfd* pollfds, int pollfds_size, int result_size); 87 void HandleEvents(struct pollfd* pollfds, int pollfds_size, int result_size);
51 void HandleTimeout(); 88 void HandleTimeout();
52 static void* Poll(void* args); 89 static void* Poll(void* args);
53 void WakeupHandler(intptr_t id, Dart_Port dart_port, int64_t data); 90 void WakeupHandler(intptr_t id, Dart_Port dart_port, int64_t data);
54 void HandleInterruptFd(); 91 void HandleInterruptFd();
55 void SetPort(intptr_t fd, Dart_Port dart_port, intptr_t mask); 92 void SetPort(intptr_t fd, Dart_Port dart_port, intptr_t mask);
56 intptr_t GetPollEvents(struct pollfd* pollfd); 93 intptr_t GetPollEvents(struct pollfd* pollfd);
57 94
58 SocketData* socket_map_; 95 SocketData* socket_map_;
59 intptr_t socket_map_entries_;
60 intptr_t socket_map_size_; 96 intptr_t socket_map_size_;
61 int64_t timeout_; // Time for next timeout. 97 int64_t timeout_; // Time for next timeout.
62 Dart_Port timeout_port_; 98 Dart_Port timeout_port_;
63 int interrupt_fds_[2]; 99 int interrupt_fds_[2];
64 }; 100 };
65 101
66 102
67 #endif // BIN_EVENTHANDLER_LINUX_H_ 103 #endif // BIN_EVENTHANDLER_LINUX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698