obj->intern->unbuffered = z_is_true(value);
}
+static void php_pqconn_object_read_nonblocking(zval *object, void *o, zval *return_value TSRMLS_DC)
+{
+ php_pqconn_object_t *obj = o;
+
+ RETVAL_BOOL(PQisnonblocking(obj->intern->conn));
+}
+
+static void php_pqconn_object_write_nonblocking(zval *object, void *o, zval *value TSRMLS_DC)
+{
+ php_pqconn_object_t *obj = o;
+
+ PQsetnonblocking(obj->intern->conn, z_is_true(value));
+}
+
static void php_pqconn_object_read_db(zval *object, void *o, zval *return_value TSRMLS_DC)
{
php_pqconn_object_t *obj = o;
}
}
+ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_flush, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqconn, flush) {
+ zend_error_handling zeh;
+ ZEND_RESULT_CODE rv;
+
+ zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
+ rv = zend_parse_parameters_none();
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+ } else if (!obj->intern->poller) {
+ throw_exce(EX_RUNTIME TSRMLS_CC, "No asynchronous operation active");
+ } else {
+ switch (PQflush(obj->intern->conn)) {
+ case -1:
+ default:
+ throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to flush connection: %s", PHP_PQerrorMessage(obj->intern->conn));
+ break;
+ case 0:
+ RETVAL_TRUE;
+ break;
+ case 1:
+ RETVAL_FALSE;
+ break;
+ }
+ }
+ }
+}
+
ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_exec, 0, 0, 1)
ZEND_ARG_INFO(0, query)
ZEND_END_ARG_INFO();
PHP_ME(pqconn, reset, ai_pqconn_reset, ZEND_ACC_PUBLIC)
PHP_ME(pqconn, resetAsync, ai_pqconn_reset_async, ZEND_ACC_PUBLIC)
PHP_ME(pqconn, poll, ai_pqconn_poll, ZEND_ACC_PUBLIC)
+ PHP_ME(pqconn, flush, ai_pqconn_flush, ZEND_ACC_PUBLIC)
PHP_ME(pqconn, exec, ai_pqconn_exec, ZEND_ACC_PUBLIC)
PHP_ME(pqconn, execAsync, ai_pqconn_exec_async, ZEND_ACC_PUBLIC)
PHP_ME(pqconn, execParams, ai_pqconn_exec_params, ZEND_ACC_PUBLIC)
php_pqconn_object_handlers.get_properties = php_pq_object_properties;
php_pqconn_object_handlers.get_debug_info = php_pq_object_debug_info;
- zend_hash_init(&php_pqconn_object_prophandlers, 20, NULL, NULL, 1);
+ zend_hash_init(&php_pqconn_object_prophandlers, 21, NULL, NULL, 1);
zend_declare_property_long(php_pqconn_class_entry, ZEND_STRL("status"), CONNECTION_BAD, ZEND_ACC_PUBLIC TSRMLS_CC);
ph.read = php_pqconn_object_read_status;
zend_hash_add(&php_pqconn_object_prophandlers, "unbuffered", sizeof("unbuffered"), (void *) &ph, sizeof(ph), NULL);
ph.write = NULL;
+ zend_declare_property_bool(php_pqconn_class_entry, ZEND_STRL("nonblocking"), 0, ZEND_ACC_PUBLIC TSRMLS_CC);
+ ph.read = php_pqconn_object_read_nonblocking;
+ ph.write = php_pqconn_object_write_nonblocking;
+ zend_hash_add(&php_pqconn_object_prophandlers, "nonblocking", sizeof("nonblocking"), (void *) &ph, sizeof(ph), NULL);
+ ph.write = NULL;
+
zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("db"), ZEND_ACC_PUBLIC TSRMLS_CC);
ph.read = php_pqconn_object_read_db;
zend_hash_add(&php_pqconn_object_prophandlers, "db", sizeof("db"), (void *) &ph, sizeof(ph), NULL);
--- /dev/null
+--TEST--
+flush
+--SKIPIF--
+<?php include "_skipif.inc"; ?>
+--FILE--
+<?php
+echo "Test\n";
+
+include "_setup.inc";
+
+$c = new pq\Connection(PQ_DSN);
+$c->nonblocking = true;
+var_dump($c->nonblocking);
+$c->execAsync("SELECT '".str_repeat("a", 6e7)."'", function($r) {
+ $r->fetchCol($s);
+ var_dump(strlen($s));
+});
+var_dump($flushed = $c->flush());
+do {
+ while (!$flushed || $c->busy) {
+ $r = $c->busy ? [$c->socket] : null;
+ $w = !$flushed ?[$c->socket] : null;
+
+ if (stream_select($r, $w, $e, null)) {
+ if ($r) {
+ printf("P%d", $c->poll());
+ }
+ if ($w) {
+ printf("F%d", $flushed = $c->flush());
+ }
+ }
+ }
+ echo "\n";
+} while ($c->getResult());
+?>
+===DONE===
+--EXPECTF--
+Test
+bool(true)
+bool(%s)
+%r(F0)*(F1)*(P3)+%r
+int(60000000)
+
+===DONE===