Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: andreiz/php-zookeeper
base: d2ee9d15e9
...
head fork: andreiz/php-zookeeper
compare: 1fa8270af8
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 2 contributors
Commits on Dec 12, 2011
Mikko Koppanen Added max_size option for ->get. Setting 0 will automatically allocat…
…e the buffer of supposedly correct size. get will return false on marshalling error
3ba278e
@andreiz Merge pull request #7 from mkoppanen/master
Issue 6
1fa8270
Showing with 30 additions and 7 deletions.
  1. +29 −6 php_zookeeper.c
  2. +1 −1  zookeeper-api.php
View
35 php_zookeeper.c
@@ -291,14 +291,15 @@ static PHP_METHOD(Zookeeper, get)
zend_fcall_info_cache fcc = empty_fcall_info_cache;
zval *stat_info = NULL;
php_cb_data_t *cb_data = NULL;
- char buffer[512];
- int buffer_len = 512;
+ char *buffer;
+ long max_size = 0;
struct Stat stat;
int status = ZOK;
+ int length;
ZK_METHOD_INIT_VARS;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|f!z", &path, &path_len, &fci,
- &fcc, &stat_info) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|f!zl", &path, &path_len, &fci,
+ &fcc, &stat_info, &max_size) == FAILURE) {
return;
}
@@ -307,11 +308,33 @@ static PHP_METHOD(Zookeeper, get)
if (fci.size != 0) {
cb_data = php_cb_data_new(&fci, &fcc, 1 TSRMLS_CC);
}
+
+ if (max_size <= 0) {
+ status = zoo_exists(i_obj->zk, path, 1, &stat);
+
+ if (status != ZOK) {
+ php_cb_data_destroy(&cb_data);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "error: %s", zerror(status));
+ return;
+ }
+ length = stat.dataLength;
+ } else {
+ length = max_size;
+ }
+
+ buffer = emalloc (length);
status = zoo_wget(i_obj->zk, path, (fci.size != 0) ? php_zk_watcher_marshal : NULL,
- cb_data, buffer, &buffer_len, &stat);
+ cb_data, buffer, &length, &stat);
+
if (status != ZOK) {
+ efree (buffer);
php_cb_data_destroy(&cb_data);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "error: %s", zerror(status));
+
+ /* Indicate data marshalling failure with boolean false so that user can retry */
+ if (status == ZMARSHALLINGERROR) {
+ RETURN_FALSE;
+ }
return;
}
@@ -319,7 +342,7 @@ static PHP_METHOD(Zookeeper, get)
zval_dtor(stat_info);
php_stat_to_array(&stat, stat_info);
}
- RETURN_STRINGL(buffer, buffer_len, 1);
+ RETURN_STRINGL(buffer, length, 0);
}
/* }}} */
View
2  zookeeper-api.php
@@ -19,7 +19,7 @@ public function delete( $path, $version = -1 ) {}
public function set( $path, $data, $version = -1, &$stat = null ) {}
- public function get( $path, $watcher_cb = null, &$stat = null) {}
+ public function get( $path, $watcher_cb = null, &$stat = null, $max_size = 0) {}
public function getChildren( $path, $watcher_cb = null ) {}

No commit comments for this range

Something went wrong with that request. Please try again.