1
0
mirror of https://github.com/danog/ext-pq.git synced 2024-11-27 12:24:52 +01:00

inverted blocking option to async

This commit is contained in:
Michael Wallner 2013-01-21 17:58:33 +01:00
parent 62733e47d1
commit a009113642
3 changed files with 17 additions and 14 deletions

View File

@ -86,7 +86,7 @@ typedef struct php_pqconn_object {
zend_object zo;
PGconn *conn;
int (*poller)(PGconn *);
unsigned blocking:1;
unsigned async:1;
} php_pqconn_object_t;
typedef enum php_pqres_fetch {
@ -336,7 +336,7 @@ static zend_object_value php_pqconn_create_object_ex(zend_class_entry *ce, PGcon
if (conn) {
o->conn = conn;
o->blocking = !PQisnonblocking(o->conn);
o->async = !PQisnonblocking(o->conn);
}
ov.handle = zend_objects_store_put((zend_object *) o, NULL, php_pqconn_object_free, NULL TSRMLS_CC);
@ -734,26 +734,26 @@ static STATUS php_pqconn_update_socket(zval *this_ptr, php_pqconn_object_t *obj
ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_construct, 0, 0, 1)
ZEND_ARG_INFO(0, dsn)
ZEND_ARG_INFO(0, block)
ZEND_ARG_INFO(0, async)
ZEND_END_ARG_INFO();
static PHP_METHOD(pqconn, __construct) {
zend_error_handling zeh;
char *dsn_str;
int dsn_len;
zend_bool block = 1;
zend_bool async = 0;
zend_replace_error_handling(EH_THROW, NULL, &zeh TSRMLS_CC);
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &dsn_str, &dsn_len, &block)) {
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &dsn_str, &dsn_len, &async)) {
php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
if (obj->conn) {
PQfinish(obj->conn);
}
if ((obj->blocking = block)) {
obj->conn = PQconnectdb(dsn_str);
} else {
if ((obj->async = async)) {
obj->conn = PQconnectStart(dsn_str);
obj->poller = (int (*)(PGconn*)) PQconnectPoll;
} else {
obj->conn = PQconnectdb(dsn_str);
}
if (SUCCESS != php_pqconn_update_socket(getThis(), obj TSRMLS_CC)) {
@ -770,16 +770,19 @@ static PHP_METHOD(pqconn, reset) {
php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
if (obj->conn) {
if (obj->blocking) {
if (obj->async) {
if (PQresetStart(obj->conn)) {
obj->poller = (int (*)(PGconn*)) PQresetPoll;
RETURN_TRUE;
}
} else {
PQreset(obj->conn);
if (CONNECTION_OK == PQstatus(obj->conn)) {
RETURN_TRUE;
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Connection reset failed: %s", PQerrorMessage(obj->conn));
}
} else if (PQresetStart(obj->conn)) {
obj->poller = (int (*)(PGconn*)) PQresetPoll;
RETURN_TRUE;
}
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Connection not initialized");

View File

@ -8,7 +8,7 @@ echo "Test\n";
include "_setup.inc";
$c = new pq\Connection(PQ_DSN, false);
$c = new pq\Connection(PQ_DSN, true);
$s = array($c->status);
echo "W";
$w = array($c->socket);

View File

@ -8,7 +8,7 @@ echo "Test\n";
include "_setup.inc";
$c = new pq\Connection(PQ_DSN, false);
$c = new pq\Connection(PQ_DSN, true);
function complete($c) {
$s = array($c->status);