Handle initial connection queries being sent partly

The CONN_STATUS_SENT_* statuses were not being handled at all, and
they indicate that a query has been sent, but not fully, so the client
should wait for the socket to become writable again and flush the output.
This commit is contained in:
Jan Urbański 2010-03-31 01:53:59 +02:00 committed by Federico Di Gregorio
parent b99eac18f8
commit 25a609c9a7
2 changed files with 17 additions and 7 deletions

View File

@ -387,7 +387,7 @@ conn_connect(connectionObject *self, long int async)
PyObject * PyObject *
conn_poll_send(connectionObject *self) conn_poll_send(connectionObject *self)
{ {
const char *query; const char *query = NULL;
int next_status; int next_status;
int ret; int ret;
@ -404,6 +404,12 @@ conn_poll_send(connectionObject *self)
query = psyco_client_encoding; query = psyco_client_encoding;
next_status = CONN_STATUS_SENT_CLIENT_ENCODING; next_status = CONN_STATUS_SENT_CLIENT_ENCODING;
break; break;
case CONN_STATUS_SENT_DATESTYLE:
case CONN_STATUS_SENT_CLIENT_ENCODING:
/* the query has only been partially sent */
query = NULL;
next_status = self->status;
break;
default: default:
/* unexpected state, error out */ /* unexpected state, error out */
PyErr_Format(OperationalError, PyErr_Format(OperationalError,
@ -416,12 +422,14 @@ conn_poll_send(connectionObject *self)
Py_BEGIN_ALLOW_THREADS; Py_BEGIN_ALLOW_THREADS;
pthread_mutex_lock(&(self->lock)); pthread_mutex_lock(&(self->lock));
if (PQsendQuery(self->pgconn, query) != 1) { if (query != NULL) {
pthread_mutex_unlock(&(self->lock)); if (PQsendQuery(self->pgconn, query) != 1) {
Py_BLOCK_THREADS; pthread_mutex_unlock(&(self->lock));
PyErr_SetString(OperationalError, Py_BLOCK_THREADS;
PQerrorMessage(self->pgconn)); PyErr_SetString(OperationalError,
return NULL; PQerrorMessage(self->pgconn));
return NULL;
}
} }
if (PQflush(self->pgconn) == 0) { if (PQflush(self->pgconn) == 0) {

View File

@ -426,7 +426,9 @@ psyco_conn_poll(connectionObject *self)
switch (self->status) { switch (self->status) {
case CONN_STATUS_SEND_DATESTYLE: case CONN_STATUS_SEND_DATESTYLE:
case CONN_STATUS_SENT_DATESTYLE:
case CONN_STATUS_SEND_CLIENT_ENCODING: case CONN_STATUS_SEND_CLIENT_ENCODING:
case CONN_STATUS_SENT_CLIENT_ENCODING:
/* these mean that we need to wait for the socket to become writable /* these mean that we need to wait for the socket to become writable
to send the rest of our query */ to send the rest of our query */
return conn_poll_send(self); return conn_poll_send(self);