]> granicus.if.org Git - php/commitdiff
Fixed bug #65015 (pg_send_query does not flush send buffer) patch submitted by: adam...
authorYasuo Ohgaki <yohgaki@php.net>
Wed, 26 Jun 2013 07:17:57 +0000 (16:17 +0900)
committerYasuo Ohgaki <yohgaki@php.net>
Wed, 26 Jun 2013 07:17:57 +0000 (16:17 +0900)
ext/pgsql/pgsql.c

index f90ba78780f8ec5676aa910bc5c728d2f219b412..1b302668afc65cd8df2c369203f1730be39f3d37 100644 (file)
@@ -4573,6 +4573,7 @@ PHP_FUNCTION(pg_send_query)
        PGconn *pgsql;
        PGresult *res;
        int leftover = 0;
+       int ret;
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs",
                                                          &pgsql_link, &query, &len) == FAILURE) {
@@ -4600,6 +4601,14 @@ PHP_FUNCTION(pg_send_query)
                        RETURN_FALSE;
                }
        }
+       /* Wait to finish sending buffer */
+       while ((ret = PQflush(pgsql))) {
+               if (ret == -1) {
+                       php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Could not empty PostgreSQL send buffer");
+                       break;
+               }
+               usleep(10000);
+       }
        if (PQ_SETNONBLOCKING(pgsql, 0)) {
                php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Cannot set connection to blocking mode");
        }
@@ -4620,6 +4629,7 @@ PHP_FUNCTION(pg_send_query_params)
        PGconn *pgsql;
        PGresult *res;
        int leftover = 0;
+       int ret;
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsa/", &pgsql_link, &query, &query_len, &pv_param_arr) == FAILURE) {
                return;
@@ -4686,6 +4696,14 @@ PHP_FUNCTION(pg_send_query_params)
                }
        }
        _php_pgsql_free_params(params, num_params);
+       /* Wait to finish sending buffer */
+       while ((ret = PQflush(pgsql))) {
+               if (ret == -1) {
+                       php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Could not empty PostgreSQL send buffer");
+                       break;
+               }
+               usleep(10000);
+       }
        if (PQ_SETNONBLOCKING(pgsql, 0)) {
                php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Cannot set connection to blocking mode");
        }
@@ -4705,6 +4723,7 @@ PHP_FUNCTION(pg_send_prepare)
        PGconn *pgsql;
        PGresult *res;
        int leftover = 0;
+       int ret;
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &pgsql_link, &stmtname, &stmtname_len, &query, &query_len) == FAILURE) {
                return;
@@ -4735,6 +4754,14 @@ PHP_FUNCTION(pg_send_prepare)
                        RETURN_FALSE;
                }
        }
+       /* Wait to finish sending buffer */
+       while ((ret = PQflush(pgsql))) {
+               if (ret == -1) {
+                       php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Could not empty postgres send buffer");
+                       break;
+               }
+               usleep(10000);
+       }
        if (PQ_SETNONBLOCKING(pgsql, 0)) {
                php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Cannot set connection to blocking mode");
        }
@@ -4757,6 +4784,7 @@ PHP_FUNCTION(pg_send_execute)
        PGconn *pgsql;
        PGresult *res;
        int leftover = 0;
+       int ret;
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsa", &pgsql_link, &stmtname, &stmtname_len, &pv_param_arr) == FAILURE) {
                return;
@@ -4823,6 +4851,14 @@ PHP_FUNCTION(pg_send_execute)
                }
        }
        _php_pgsql_free_params(params, num_params);
+       /* Wait to finish sending buffer */
+       while ((ret = PQflush(pgsql))) {
+               if (ret == -1) {
+                       php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Could not empty postgres send buffer");
+                       break;
+               }
+               usleep(10000);
+       }
        if (PQ_SETNONBLOCKING(pgsql, 0)) {
                php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Cannot set connection to blocking mode");
        }