+typedef struct php_pqconn_resource_factory_data {
+ char *dsn;
+ long flags;
+} php_pqconn_resource_factory_data_t;
+
+static php_pqconn_resource_factory_data_t *php_pqconn_resource_factory_data_init(const char *dsn, long flags)
+{
+ php_pqconn_resource_factory_data_t *data = emalloc(sizeof(*data));
+
+ data->dsn = estrdup(dsn);
+ data->flags = flags;
+
+ return data;
+}
+
+static void php_pqconn_resource_factory_data_dtor(void *d)
+{
+ php_pqconn_resource_factory_data_t *data = d;
+
+ efree(data->dsn);
+ efree(data);
+}
+
+static void *php_pqconn_resource_factory_ctor(void *data, void *init_arg TSRMLS_DC)
+{
+ php_pqconn_resource_factory_data_t *o = init_arg;
+
+ if (o->flags & PHP_PQCONN_ASYNC) {
+ return PQconnectStart(o->dsn);
+ } else {
+ return PQconnectdb(o->dsn);
+ }
+}
+
+static void php_pqconn_resource_factory_dtor(void *opaque, void *handle TSRMLS_DC)
+{
+ PQfinish(handle);
+}
+
+static php_resource_factory_ops_t php_pqconn_resource_factory_ops = {
+ php_pqconn_resource_factory_ctor,
+ NULL,
+ php_pqconn_resource_factory_dtor
+};
+