[dovecot-cvs] dovecot/src/lib-sql driver-mysql.c, 1.8,
1.9 driver-pgsql.c, 1.2, 1.3 sql-api-private.h, 1.2,
1.3 sql-api.c, 1.3, 1.4 sql-api.h, 1.2, 1.3
cras at dovecot.org
cras at dovecot.org
Thu Jun 9 21:44:24 EEST 2005
- Previous message: [dovecot-cvs] dovecot/src/lib-sql driver-mysql.c,1.7,1.8
- Next message: [dovecot-cvs] dovecot/src/auth db-sql.c, 1.1, 1.2 db-sql.h, 1.1,
1.2 passdb-sql.c, 1.18, 1.19 userdb-sql.c, 1.8, 1.9
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /var/lib/cvs/dovecot/src/lib-sql
In directory talvi:/tmp/cvs-serv6745
Modified Files:
driver-mysql.c driver-pgsql.c sql-api-private.h sql-api.c
sql-api.h
Log Message:
Added sql_connect() to do explicit connecting. sql_init() no longer does.
Index: driver-mysql.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-sql/driver-mysql.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- driver-mysql.c 9 Jun 2005 18:31:43 -0000 1.8
+++ driver-mysql.c 9 Jun 2005 18:44:22 -0000 1.9
@@ -134,15 +134,20 @@
}
}
-static void driver_mysql_connect_all(struct mysql_db *db)
+static int driver_mysql_connect_all(struct sql_db *_db)
{
+ struct mysql_db *db = (struct mysql_db *)_db;
struct mysql_connection *conn;
size_t i, size;
+ int ret = -1;
conn = buffer_get_modifyable_data(db->connections, &size);
size /= sizeof(*conn);
- for (i = 0; i < size; i++)
- (void)driver_mysql_connect(&conn[i]);
+ for (i = 0; i < size; i++) {
+ if (driver_mysql_connect(&conn[i]))
+ ret = 1;
+ }
+ return ret;
}
static void driver_mysql_connection_add(struct mysql_db *db, const char *host)
@@ -234,7 +239,6 @@
sizeof(struct mysql_connection) * 6);
driver_mysql_parse_connect_string(db, connect_string);
- driver_mysql_connect_all(db);
return &db->api;
}
@@ -468,6 +472,7 @@
driver_mysql_init,
driver_mysql_deinit,
driver_mysql_get_flags,
+ driver_mysql_connect_all,
driver_mysql_exec,
driver_mysql_query
};
Index: driver-pgsql.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-sql/driver-pgsql.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- driver-pgsql.c 26 Feb 2005 23:16:51 -0000 1.2
+++ driver-pgsql.c 9 Jun 2005 18:44:22 -0000 1.3
@@ -121,14 +121,15 @@
}
}
-static void driver_pgsql_connect(struct pgsql_db *db)
+static int driver_pgsql_connect(struct sql_db *_db)
{
+ struct pgsql_db *db = (struct pgsql_db *)_db;
time_t now;
/* don't try reconnecting more than once a second */
now = time(NULL);
if (db->connecting || db->last_connect == now)
- return;
+ return db->connected ? 1 : (db->connecting ? 0 : -1);
db->last_connect = now;
db->pg = PQconnectStart(db->connect_string);
@@ -139,12 +140,14 @@
i_error("pgsql: Connect failed to %s: %s",
PQdb(db->pg), last_error(db));
driver_pgsql_close(db);
+ return -1;
} else {
/* nonblocking connecting begins. */
db->io = io_add(PQsocket(db->pg), IO_WRITE,
connect_callback, db);
db->io_dir = IO_WRITE;
db->connecting = TRUE;
+ return 0;
}
}
@@ -156,8 +159,6 @@
db->connect_string = i_strdup(connect_string);
db->api = driver_pgsql_db;
db->queue_tail = &db->queue;
-
- (void)driver_pgsql_connect(db);
return &db->api;
}
@@ -327,7 +328,7 @@
return;
if (!db->connected) {
- driver_pgsql_connect(db);
+ driver_pgsql_connect(&db->api);
return;
}
@@ -369,7 +370,7 @@
if (!db->connected) {
/* try connecting again */
- driver_pgsql_connect(db);
+ driver_pgsql_connect(&db->api);
driver_pgsql_queue_query(result, query);
return;
}
@@ -559,6 +560,7 @@
driver_pgsql_init,
driver_pgsql_deinit,
driver_mysql_get_flags,
+ driver_pgsql_connect,
driver_pgsql_exec,
driver_pgsql_query
};
Index: sql-api-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-sql/sql-api-private.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- sql-api-private.h 26 Feb 2005 23:16:51 -0000 1.2
+++ sql-api-private.h 9 Jun 2005 18:44:22 -0000 1.3
@@ -9,6 +9,7 @@
enum sql_db_flags (*get_flags)(struct sql_db *db);
+ int (*connect)(struct sql_db *db);
void (*exec)(struct sql_db *db, const char *query);
void (*query)(struct sql_db *db, const char *query,
sql_query_callback_t *callback, void *context);
Index: sql-api.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-sql/sql-api.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- sql-api.c 26 Feb 2005 23:19:09 -0000 1.3
+++ sql-api.c 9 Jun 2005 18:44:22 -0000 1.4
@@ -23,14 +23,19 @@
db->deinit(db);
}
-void sql_exec(struct sql_db *db, const char *query)
+enum sql_db_flags sql_get_flags(struct sql_db *db)
{
- db->exec(db, query);
+ return db->get_flags(db);
}
-enum sql_db_flags sql_get_flags(struct sql_db *db)
+int sql_connect(struct sql_db *db)
{
- return db->get_flags(db);
+ return db->connect(db);
+}
+
+void sql_exec(struct sql_db *db, const char *query)
+{
+ db->exec(db, query);
}
void sql_query(struct sql_db *db, const char *query,
Index: sql-api.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-sql/sql-api.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- sql-api.h 26 Feb 2005 23:16:51 -0000 1.2
+++ sql-api.h 9 Jun 2005 18:44:22 -0000 1.3
@@ -22,6 +22,11 @@
/* Returns SQL database state flags. */
enum sql_db_flags sql_get_flags(struct sql_db *db);
+/* Explicitly connect to the database. It's not required to call this function
+ though. Returns -1 if we're not connected, 0 if we started connecting or
+ 1 if we are fully connected now. */
+int sql_connect(struct sql_db *db);
+
/* Execute SQL query without waiting for results. */
void sql_exec(struct sql_db *db, const char *query);
/* Execute SQL query and return result in callback. */
- Previous message: [dovecot-cvs] dovecot/src/lib-sql driver-mysql.c,1.7,1.8
- Next message: [dovecot-cvs] dovecot/src/auth db-sql.c, 1.1, 1.2 db-sql.h, 1.1,
1.2 passdb-sql.c, 1.18, 1.19 userdb-sql.c, 1.8, 1.9
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the dovecot-cvs
mailing list