inverted blocking option to async
authorMichael Wallner <mike@php.net>
Mon, 21 Jan 2013 16:58:33 +0000 (17:58 +0100)
committerMichael Wallner <mike@php.net>
Mon, 21 Jan 2013 16:58:33 +0000 (17:58 +0100)
src/php_pq.c
tests/async001.phpt
tests/async002.phpt

index 6058057de9e78754a6279c93c6d6deed0856e21c..ce191b3ca3bf57a4547813f814ac637bc897c5c4 100644 (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");
index 9fa2eb70a34aba0df7c85b734051e5543a0795cf..23278574a4402eb4fd8707719a47e681aa8ed95f 100644 (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);
index 3dd80d18973f7787c45af35787a8a08dec81f2f7..16de35a421dc7b79d119c2a86dadb55220119b84 100644 (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);