Permalink
Browse files

Merge branch 'master' of github.com:andreiz/php-zookeeper

  • Loading branch information...
2 parents 6c59e82 + 1fa8270 commit 4c8e6ca3b250a7a9e2c0e3a7c37cdaf45e093d2f @andreiz andreiz committed Jan 13, 2012
Showing with 30 additions and 7 deletions.
  1. +29 −6 php_zookeeper.c
  2. +1 −1 zookeeper-api.php
View
@@ -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,19 +308,41 @@ 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;
}
if (stat_info) {
zval_dtor(stat_info);
php_stat_to_array(&stat, stat_info);
}
- RETURN_STRINGL(buffer, buffer_len, 1);
+ RETURN_STRINGL(buffer, length, 0);
}
/* }}} */
View
@@ -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 ) {}

0 comments on commit 4c8e6ca

Please sign in to comment.