Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 196 lines (148 sloc) 3.231 kB
b4a1a3f @brixen Header files conditionalized for Windows (luislavena).
brixen authored
1 #ifndef RBX_WINDOWS
647f9a2 QueryAgent supports multiple clients, more commands
Evan Phoenix authored
2 #include <sys/select.h>
b4a1a3f @brixen Header files conditionalized for Windows (luislavena).
brixen authored
3 #endif
647f9a2 QueryAgent supports multiple clients, more commands
Evan Phoenix authored
4 #include <vector>
5
1dbea76 @brixen Improve handling of auxiliary threads across process changes.
brixen authored
6 #include "auxiliary_threads.hpp"
7 #include "gc/managed.hpp"
ff881b8 Started query agent, mainly just groundwork thus far
Evan Phoenix authored
8 #include "util/thread.hpp"
9
236c04e @brixen Handle stupid definition of FD_SET.
brixen authored
10 #include "windows_compat.h"
11
ff881b8 Started query agent, mainly just groundwork thus far
Evan Phoenix authored
12 namespace rubinius {
647f9a2 QueryAgent supports multiple clients, more commands
Evan Phoenix authored
13 class SharedState;
14
d087929 Revamp agent API, add a number of variables
Evan Phoenix authored
15 namespace agent {
16 class VariableAccess;
3f2cf0a Add ruby dispatch support to the agent
Evan Phoenix authored
17 class Output;
d087929 Revamp agent API, add a number of variables
Evan Phoenix authored
18 }
19
1dbea76 @brixen Improve handling of auxiliary threads across process changes.
brixen authored
20 class QueryAgent : public AuxiliaryThread, public Lockable {
90bd0fa @evanphx Lock down the agent to the current machine and user
evanphx authored
21 struct Client {
22 enum State {
23 eUnknown,
24 eWaitingAuth,
25 eRunning
26 } state;
27
28 int socket;
29 int auth_key;
30
31 Client(int s)
32 : state(eUnknown)
33 , socket(s)
1dbea76 @brixen Improve handling of auxiliary threads across process changes.
brixen authored
34 , auth_key(0)
90bd0fa @evanphx Lock down the agent to the current machine and user
evanphx authored
35 {}
36
37 void set_running() {
38 state = eRunning;
39 }
40
41 bool needs_auth_p() {
42 return state == eWaitingAuth;
43 }
44
45 void begin_auth(int key) {
46 auth_key = key;
47 state = eWaitingAuth;
48 }
49
50 };
51
cb9e8b0 @ryoqun Move thread under rubinius::utilities::thread
ryoqun authored
52 class Thread : public utilities::thread::Thread {
1dbea76 @brixen Improve handling of auxiliary threads across process changes.
brixen authored
53 private:
54 QueryAgent* agent_;
55 bool exit_;
56
57 public:
58 Thread(QueryAgent* agent);
59
60 void stop();
61 virtual void perform();
62 };
63
90bd0fa @evanphx Lock down the agent to the current machine and user
evanphx authored
64 private:
647f9a2 QueryAgent supports multiple clients, more commands
Evan Phoenix authored
65 SharedState& shared_;
1dbea76 @brixen Improve handling of auxiliary threads across process changes.
brixen authored
66 Thread* thread_;
ff881b8 Started query agent, mainly just groundwork thus far
Evan Phoenix authored
67 int port_;
68 int server_fd_;
69 bool verbose_;
647f9a2 QueryAgent supports multiple clients, more commands
Evan Phoenix authored
70 fd_set fds_;
71 int max_fd_;
72
b9d29f0 Add Rubinius::Agent and agent loopback connection
Evan Phoenix authored
73 int control_[2];
74 int loopback_[2];
75
3f2cf0a Add ruby dispatch support to the agent
Evan Phoenix authored
76 int a2r_[2];
77 int r2a_[2];
78
90bd0fa @evanphx Lock down the agent to the current machine and user
evanphx authored
79 std::vector<Client> sockets_;
ff881b8 Started query agent, mainly just groundwork thus far
Evan Phoenix authored
80
d087929 Revamp agent API, add a number of variables
Evan Phoenix authored
81 agent::VariableAccess* vars_;
82
90bd0fa @evanphx Lock down the agent to the current machine and user
evanphx authored
83 bool local_only_;
845ab59 @evanphx Add password authentication to the agent
evanphx authored
84 bool use_password_;
85 std::string password_;
90bd0fa @evanphx Lock down the agent to the current machine and user
evanphx authored
86 uint32_t tmp_key_;
87
ff881b8 Started query agent, mainly just groundwork thus far
Evan Phoenix authored
88 const static int cBackLog = 10;
89
90 public:
1dbea76 @brixen Improve handling of auxiliary threads across process changes.
brixen authored
91 QueryAgent(STATE);
a91f7a3 @dbussink Properly setup destructors for new AuxiliaryThread class
dbussink authored
92 virtual ~QueryAgent();
ff881b8 Started query agent, mainly just groundwork thus far
Evan Phoenix authored
93
94 void set_verbose() {
95 verbose_ = true;
96 }
97
436e637 Allow for a random server port to be used
Evan Phoenix authored
98 int port() {
99 return port_;
100 }
101
1dbea76 @brixen Improve handling of auxiliary threads across process changes.
brixen authored
102 fd_set fds() {
103 return fds_;
104 }
105
106 int max_fd() {
107 return max_fd_;
108 }
109
110 int server_fd() {
111 return server_fd_;
112 }
113
114 bool local_only() {
115 return local_only_;
116 }
117
118 bool use_password() {
119 return use_password_;
120 }
121
122 bool verbose() {
123 return verbose_;
124 }
125
126 uint32_t incr_tmp_key() {
127 return tmp_key_++;
128 }
129
130 void add_socket(Client client) {
131 sockets_.push_back(client);
35a49f3 @evanphx Introduce State class as STATE
evanphx authored
132 }
133
b9d29f0 Add Rubinius::Agent and agent loopback connection
Evan Phoenix authored
134 void add_fd(int fd) {
0d433ca @brixen Fixes, workarounds, stubs to compile agent.cpp.
brixen authored
135 FD_SET((int_fd_t)fd, &fds_);
b9d29f0 Add Rubinius::Agent and agent loopback connection
Evan Phoenix authored
136 if(fd > max_fd_) max_fd_ = fd;
137 }
138
139 void remove_fd(int fd) {
0d433ca @brixen Fixes, workarounds, stubs to compile agent.cpp.
brixen authored
140 FD_CLR((int_fd_t)fd, &fds_);
b9d29f0 Add Rubinius::Agent and agent loopback connection
Evan Phoenix authored
141 }
142
143 int loopback_socket() {
144 return loopback_[1];
145 }
146
147 int read_control() {
148 return control_[0];
149 }
150
151 int write_control() {
152 return control_[1];
153 }
154
3f2cf0a Add ruby dispatch support to the agent
Evan Phoenix authored
155 int a2r_agent() {
156 return a2r_[1];
157 }
158
159 int a2r_ruby() {
160 return a2r_[0];
161 }
162
163 int r2a_agent() {
164 return r2a_[0];
165 }
166
167 int r2a_ruby() {
168 return r2a_[1];
169 }
170
1dbea76 @brixen Improve handling of auxiliary threads across process changes.
brixen authored
171 void initialize(STATE);
172 void start_thread(STATE);
173 void stop_thread(STATE);
32c35a4 @dbussink Trigger a wakeup after setting up the listening socket for the agent
dbussink authored
174 void wakeup();
b9d29f0 Add Rubinius::Agent and agent loopback connection
Evan Phoenix authored
175
176 bool setup_local();
177 bool bind(int port);
0051012 Allow loopback agent to bind to a TCP port
Evan Phoenix authored
178
179 void make_discoverable();
180
845ab59 @evanphx Add password authentication to the agent
evanphx authored
181 bool check_password(Client& client);
182 bool check_file_auth(Client& client);
90bd0fa @evanphx Lock down the agent to the current machine and user
evanphx authored
183 bool process_commands(Client& client);
1dbea76 @brixen Improve handling of auxiliary threads across process changes.
brixen authored
184 bool process_clients(fd_set fds);
e27f185 Disable the agent in forks and cleanup before exec
Evan Phoenix authored
185
186 void cleanup();
089edc7 @brixen Remove the Agent thread before exec().
brixen authored
187
1dbea76 @brixen Improve handling of auxiliary threads across process changes.
brixen authored
188 void shutdown(STATE);
189 void before_exec(STATE);
190 void after_exec(STATE);
191 void before_fork(STATE);
192 void after_fork_parent(STATE);
193 void after_fork_child(STATE);
ff881b8 Started query agent, mainly just groundwork thus far
Evan Phoenix authored
194 };
195 }
Something went wrong with that request. Please try again.