diff options
author | Russ Allbery <rra@stanford.edu> | 2011-10-31 16:21:28 -0700 |
---|---|---|
committer | Russ Allbery <rra@stanford.edu> | 2011-10-31 16:21:28 -0700 |
commit | d6add1e7a9e730e86f93382ab4cadd95b14a4af7 (patch) | |
tree | aa05ddc03808912c21cb98dad86956c5a377a6d0 /ruby | |
parent | 2fe0f67e442dab9c23fff4ec56120888d59c9559 (diff) |
Add NOOP support to the language bindings
Diffstat (limited to 'ruby')
-rw-r--r-- | ruby/README | 18 | ||||
-rw-r--r-- | ruby/remctl.c | 21 | ||||
-rw-r--r-- | ruby/test_remctl.rb.in | 1 |
3 files changed, 40 insertions, 0 deletions
diff --git a/ruby/README b/ruby/README index 2271048..d3f2f2f 100644 --- a/ruby/README +++ b/ruby/README @@ -179,11 +179,29 @@ FULL INTERFACE Exceptions: + * Remctl::Error: a network or authentication error occurred * Remctl::NotOpen: no connection currently open Errors from the server are returned as an error token, not as an exception. + r.noop() + Send a NOOP message to the server and read the reply. This is + primarily used to keep a connection to a remctl server alive, such + as through a firewall with a session timeout, while waiting to issue + further commands. Returns true on success, false on failure. + + The NOOP message requires protocol version 3 support in the server, + so the caller should be prepared for this function to fail, + indicating that the connection could not be kept alive and possibly + that it was closed by the server. In this case, the client will + need to explicitly reopen the connection with open(). + + Exceptions: + + * Remctl::Error: a network or authentication error occurred + * Remctl::NotOpen: no connection currently open + r.close() Close a connection. After calling this method, #reopen must be called for this object before sending any further commands. The diff --git a/ruby/remctl.c b/ruby/remctl.c index 8ec587a..b5a46d6 100644 --- a/ruby/remctl.c +++ b/ruby/remctl.c @@ -456,6 +456,26 @@ rb_remctl_output(VALUE self) /* call-seq: + * r.noop() -> nil + * + * Send a NOOP message and read the reply. Returns nil. + * + * Raises Remctl::Error in the event of failure, and Remctl::NotOpen if the + * connection has been closed. + */ +static VALUE +rb_remctl_noop(VALUE self) +{ + struct remctl *r; + + GET_REMCTL_OR_RAISE(self, r); + if (!remctl_noop(r)) + rb_raise(eRemctlError, "%s", remctl_error(r)); + return Qnil; +} + + +/* call-seq: * Remctl.new(host, port=Remctl.default_port, princ=Remctl.default_principal) -> #<Remctl> * Remctl.new(host, port, princ) {|r| ...} -> nil * @@ -552,6 +572,7 @@ Init_remctl(void) rb_define_method(cRemctl, "reopen", rb_remctl_reopen, 0); rb_define_method(cRemctl, "command", rb_remctl_command, -1); rb_define_method(cRemctl, "output", rb_remctl_output, 0); + rb_define_method(cRemctl, "noop", rb_remctl_noop, 0); /* Document-class: Remctl::Result * diff --git a/ruby/test_remctl.rb.in b/ruby/test_remctl.rb.in index 6c37e3b..f6eb635 100644 --- a/ruby/test_remctl.rb.in +++ b/ruby/test_remctl.rb.in @@ -173,6 +173,7 @@ class TC_RemctlFull < Test::Unit::TestCase assert_equal(output[3], 0) output = r.output assert_equal(output[0], :done) + r.noop r.close end |