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 /php | |
parent | 2fe0f67e442dab9c23fff4ec56120888d59c9559 (diff) |
Add NOOP support to the language bindings
Diffstat (limited to 'php')
-rw-r--r-- | php/README | 13 | ||||
-rw-r--r-- | php/php_remctl.c | 23 | ||||
-rw-r--r-- | php/php_remctl.h.in | 1 | ||||
-rw-r--r-- | php/tests/003.phpt | 6 |
4 files changed, 43 insertions, 0 deletions
@@ -187,6 +187,18 @@ FULL INTERFACE For an "error" token, returns the remctl error code for the protocol error. The text message will be returned in data. + remctl_noop(CONNECTION) + 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 remctl_open. + remctl_close(CONNECTION) Explicitly close the connection and destroy the connection object. This will also be done automatically when the object is destroyed, @@ -237,6 +249,7 @@ FULL INTERFACE echo "remctl_output failed: " . remctl_error($r) . "\n"; exit(2); } + remctl_noop($r) remctl_close($r) As mentioned above, the final remctl_close() is normally not needed. diff --git a/php/php_remctl.c b/php/php_remctl.c index 7bedcf8..f917343 100644 --- a/php/php_remctl.c +++ b/php/php_remctl.c @@ -37,6 +37,7 @@ static zend_function_entry remctl_functions[] = { ZEND_FE(remctl_close, NULL) ZEND_FE(remctl_command, NULL) ZEND_FE(remctl_output, NULL) + ZEND_FE(remctl_noop, NULL) ZEND_FE(remctl_error, NULL) { NULL, NULL, NULL, 0, 0 } }; @@ -439,6 +440,28 @@ ZEND_FUNCTION(remctl_output) /* + * Sends a NOOP message to the server and reads the reply. + */ +ZEND_FUNCTION(remctl_noop) +{ + struct remctl *r; + zval *zrem; + int status; + + status = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zrem); + if (status == FAILURE) { + zend_error(E_WARNING, "remctl_noop: invalid parameters\n"); + RETURN_FALSE; + } + ZEND_FETCH_RESOURCE(r, struct remctl *, &zrem, -1, PHP_REMCTL_RES_NAME, + le_remctl_internal); + if (!remctl_noop(r)) + RETURN_FALSE; + RETURN_TRUE; +} + + +/* * Returns the error message from a previously failed remctl call. */ ZEND_FUNCTION(remctl_error) diff --git a/php/php_remctl.h.in b/php/php_remctl.h.in index 26f7f89..895435b 100644 --- a/php/php_remctl.h.in +++ b/php/php_remctl.h.in @@ -25,6 +25,7 @@ PHP_FUNCTION(remctl_set_source_ip); PHP_FUNCTION(remctl_open); PHP_FUNCTION(remctl_command); PHP_FUNCTION(remctl_output); +PHP_FUNCTION(remctl_noop); PHP_FUNCTION(remctl_error); PHP_FUNCTION(remctl_close); diff --git a/php/tests/003.phpt b/php/tests/003.phpt index cffaf56..0bce1ca 100644 --- a/php/tests/003.phpt +++ b/php/tests/003.phpt @@ -23,6 +23,11 @@ LD_LIBRARY_PATH=../client/.libs exit(2); } echo "Opened connection\n"; + if (!remctl_noop($r)) { + echo "remctl_noop failed\n"; + exit(2); + } + echo "Send NOOP message\n"; $args = array("test", "test"); if (!remctl_command($r, $args)) { echo "remctl_command failed\n"; @@ -63,6 +68,7 @@ LD_LIBRARY_PATH=../client/.libs --EXPECT-- Created object Opened connection +Send NOOP message Sent command 1: output 1: (stream 1) hello world |