Changeset 771:eac79a449c06 in freeDiameter for extensions/app_acct
- Timestamp:
- Oct 31, 2011, 4:57:59 AM (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/app_acct/acct_db.c
r741 r771 36 36 /* Database interface module */ 37 37 38 /* There is one connection to the db per thread. 39 The connection is stored in the pthread_key_t variable */ 40 41 38 42 #include "app_acct.h" 39 43 #include <libpq-fe.h> … … 54 58 static 55 59 #endif /* TEST_DEBUG */ 56 PGconn *conn = NULL; 60 pthread_key_t connk; 61 57 62 58 63 /* Initialize the database context: connection to the DB, prepared statement to insert new records */ … … 66 71 int idx = 0; 67 72 PGresult * res; 73 PGconn *conn; 68 74 #define REALLOC_SIZE 1024 /* We extend the buffer by this amount */ 69 75 … … 195 201 acct_rec_empty(&emptyrecords); 196 202 203 CHECK_POSIX( pthread_key_create(&connk, (void (*)(void*))PQfinish) ); 204 CHECK_POSIX( pthread_setspecific(connk, conn) ); 205 197 206 /* Ok, ready */ 198 207 return 0; … … 202 211 void acct_db_free(void) 203 212 { 204 if (conn) { 205 /* Note: the prepared statement is automatically freed when the session terminates */ 206 PQfinish(conn); 207 conn = NULL; 208 } 213 CHECK_POSIX_DO(pthread_key_delete(connk) , ); 209 214 } 210 215 … … 219 224 PGresult *res; 220 225 struct fd_list *li; 226 PGconn *conn; 221 227 222 228 TRACE_ENTRY("%p", records); 223 CHECK_PARAMS( conn && records ); 229 CHECK_PARAMS( records ); 230 231 conn = pthread_getspecific(connk); 232 if (!conn) { 233 conn = PQconnectdb(acct_config->conninfo); 234 CHECK_POSIX( pthread_setspecific(connk, conn) ); 235 } 224 236 225 237 /* First, check if the connection with the DB has not staled, and eventually try to fix it */
Note: See TracChangeset
for help on using the changeset viewer.