forked from rubinius/rubinius
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QueryAgent supports multiple clients, more commands
QueryAgent knows: t[:uname] => [..] t[:set_config, "key", "val"] => :ok t[:get_config, "key"] => [:ok, ...] :close => :bye
- Loading branch information
Evan Phoenix
committed
Oct 30, 2009
1 parent
f2849f0
commit 647f9a2
Showing
6 changed files
with
292 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require 'rubygems' | ||
require 'bert' | ||
require 'bert/decode' | ||
require 'socket' | ||
|
||
class Agent | ||
def initialize(port) | ||
@socket = TCPSocket.new("localhost", port) | ||
p decode() | ||
end | ||
|
||
def decode | ||
decoder = BERT::Decode.new @socket | ||
decoder.read_any | ||
end | ||
|
||
def uname | ||
enc = BERT.encode t[:uname] | ||
@socket << enc | ||
decode | ||
end | ||
|
||
def close | ||
@socket << BERT.encode(:close) | ||
decode | ||
end | ||
|
||
def get_config(key) | ||
@socket << BERT.encode(t[:get_config, key.to_s]) | ||
decode | ||
end | ||
|
||
def set_config(key, val) | ||
@socket << BERT.encode(t[:set_config, key.to_s, val.to_s]) | ||
decode | ||
end | ||
end | ||
|
||
agent = Agent.new(ARGV.shift.to_i) | ||
|
||
p agent.uname | ||
# agent.close | ||
|
||
p agent.get_config("gc.bytes") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,41 @@ | ||
#include <sys/select.h> | ||
#include <vector> | ||
|
||
#include "util/thread.hpp" | ||
|
||
namespace rubinius { | ||
class SharedState; | ||
|
||
class QueryAgent : public thread::Thread { | ||
SharedState& shared_; | ||
int port_; | ||
int server_fd_; | ||
bool verbose_; | ||
fd_set fds_; | ||
int max_fd_; | ||
|
||
std::vector<int> sockets_; | ||
|
||
const static int cBackLog = 10; | ||
|
||
public: | ||
QueryAgent(int port) | ||
QueryAgent(SharedState& shared, int port) | ||
: Thread() | ||
, shared_(shared) | ||
, port_(port) | ||
, server_fd_(0) | ||
, verbose_(false) | ||
{} | ||
, max_fd_(0) | ||
{ | ||
FD_ZERO(&fds_); | ||
} | ||
|
||
void set_verbose() { | ||
verbose_ = true; | ||
} | ||
|
||
void bind(); | ||
bool bind(); | ||
virtual void perform(); | ||
bool process_commands(int client); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.