summaryrefslogtreecommitdiff
path: root/psycopg/psycopgmodule.c
diff options
context:
space:
mode:
authorFederico Di Gregorio <fog@initd.org>2010-04-05 11:30:03 +0200
committerFederico Di Gregorio <fog@initd.org>2010-04-05 11:30:03 +0200
commit34317dc4c3686d48dd58756ad4edd9b6942567c8 (patch)
tree62a420cbad8802cfcea059a3eadf35a8f75a119c /psycopg/psycopgmodule.c
parent1f6ffbba0f24537648c51384a72b72bff27499b1 (diff)
downloadpsycopg2-34317dc4c3686d48dd58756ad4edd9b6942567c8.tar.gz
Support asynchronous connection building
After calling psycopg2.connect(dsn, async=True) you can poll the connection that will tell you whether its file descriptor should be waited on to become writable or readable or that the connection attempt has succeeded. Edited commit by Jan to not expose internal state in extensions.py.
Diffstat (limited to 'psycopg/psycopgmodule.c')
-rw-r--r--psycopg/psycopgmodule.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c
index 7726319..8ececea 100644
--- a/psycopg/psycopgmodule.c
+++ b/psycopg/psycopgmodule.c
@@ -90,6 +90,7 @@ HIDDEN int psycopg_debug_enabled = 0;
"- ``user`` -- user name used to authenticate\n" \
"- ``password`` -- password used to authenticate\n" \
"- ``sslmode`` -- SSL mode (see PostgreSQL documentation)\n\n" \
+"- ``async`` -- if the connection should provide asynchronous API\n\n" \
"If the ``connection_factory`` keyword argument is not provided this\n" \
"function always return an instance of the `connection` class.\n" \
"Else the given sub-class of `extensions.connection` will be used to\n" \
@@ -118,14 +119,16 @@ psyco_connect(PyObject *self, PyObject *args, PyObject *keywds)
const char *database=NULL, *user=NULL, *password=NULL;
const char *host=NULL, *sslmode=NULL;
char port[16];
+ int async = 0;
static char *kwlist[] = {"dsn", "database", "host", "port",
"user", "password", "sslmode",
- "connection_factory", NULL};
+ "connection_factory", "async", NULL};
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "|sssOsssO", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "|sssOsssOi", kwlist,
&dsn_static, &database, &host, &pyport,
- &user, &password, &sslmode, &factory)) {
+ &user, &password, &sslmode,
+ &factory, &async)) {
return NULL;
}
@@ -190,11 +193,11 @@ psyco_connect(PyObject *self, PyObject *args, PyObject *keywds)
{
const char *dsn = (dsn_static != NULL ? dsn_static : dsn_dynamic);
- Dprintf("psyco_connect: dsn = '%s'", dsn);
+ Dprintf("psyco_connect: dsn = '%s', async = %d", dsn, async);
/* allocate connection, fill with errors and return it */
if (factory == NULL) factory = (PyObject *)&connectionType;
- conn = PyObject_CallFunction(factory, "s", dsn);
+ conn = PyObject_CallFunction(factory, "si", dsn, async);
}
goto cleanup;