inst->config = rad_malloc(sizeof(SQL_CONFIG));
memset(inst->config, 0, sizeof(SQL_CONFIG));
-#if HAVE_PTHREAD_H
- inst->lock = (pthread_mutex_t *) rad_malloc(sizeof(pthread_mutex_t));
- pthread_mutex_init(inst->lock, NULL);
-
- inst->notfull = (pthread_cond_t *) rad_malloc(sizeof(pthread_cond_t));
- pthread_cond_init(inst->notfull, NULL);
-#endif
-
/*
* If the configuration parameters can't be parsed, then
* fail.
sqlsocket->state = sockunconnected;
#if HAVE_PTHREAD_H
+ /*
+ * FIXME! Check return codes!
+ */
sqlsocket->semaphore = (sem_t *) rad_malloc(sizeof(sem_t));
sem_init(sqlsocket->semaphore, 0, SQLSOCK_UNLOCKED);
#else
- sqlsocket->in_use = 0;
+ sqlsocket->in_use = SQLSOCK_UNLOCKED;
#endif
if (time(NULL) > inst->connect_after) {
for (cur = inst->sqlpool; cur; cur = cur->next) {
sql_close_socket(inst, cur);
}
-#if HAVE_PTHREAD_H
- pthread_mutex_destroy(inst->lock);
- pthread_cond_destroy(inst->notfull);
-#endif
}
struct timeval timeout;
int tried_to_connect = 0;
-#if HAVE_PTHREAD_H
- pthread_mutex_lock(inst->lock);
-#endif
while (inst->used == inst->config->num_sql_socks) {
- radlog(L_DBG, "rlm_sql: Waiting for open sql socket");
-#if HAVE_PTHREAD_H
- pthread_cond_wait(inst->notfull, inst->lock);
-#else
- /* this should be portable... */
- timeout.tv_sec = 0;
- timeout.tv_usec = 200;
- select(0, NULL, NULL, NULL, &timeout)
-#endif
+ radlog(L_ERR, "rlm_sql: All sockets are being used! Please increase the maximum number of sockets!");
+ return NULL;
}
for (cur = inst->sqlpool; cur; cur = cur->next) {
if (cur->in_use == SQLSOCK_UNLOCKED) {
#endif
(inst->used)++;
-#if HAVE_PTHREAD_H
- pthread_mutex_unlock(inst->lock);
-#else
+#ifne HAVE_PTHREAD_H
cur->in_use = SQLSOCK_LOCKED;
#endif
radlog(L_DBG, "rlm_sql: Reserving sql socket id: %d", cur->id);
}
}
-#if HAVE_PTHREAD_H
- pthread_mutex_unlock(inst->lock);
-#endif
-
/* We get here if every DB handle is unconnected and unconnectABLE */
radlog((tried_to_connect = 0) ? (L_DBG) : (L_CONS | L_ERR), "rlm_sql: There are no DB handles to use!");
return NULL;
*************************************************************************/
int sql_release_socket(SQL_INST * inst, SQLSOCK * sqlsocket) {
-#if HAVE_PTHREAD_H
- pthread_mutex_lock(inst->lock);
-#endif
(inst->used)--;
#if HAVE_PTHREAD_H
sem_post(sqlsocket->semaphore);
#else
- sqlsocket->in_use = 0;
+ sqlsocket->in_use = SQLSOCK_UNLOCKED;
#endif
radlog(L_DBG, "rlm_sql: Released sql socket id: %d", sqlsocket->id);
-#if HAVE_PTHREAD_H
- pthread_mutex_unlock(inst->lock);
- pthread_cond_signal(inst->notfull);
-#endif
-
return 1;
}