- return value cleanup

This commit is contained in:
Martin Willi
2005-11-28 20:29:47 +00:00
parent 3fe058703f
commit d048df5cab
85 changed files with 1086 additions and 2680 deletions
+3 -17
View File
@@ -61,8 +61,6 @@ struct private_receiver_t {
* logger for the receiver
*/
logger_t *logger;
};
/**
@@ -84,15 +82,8 @@ static void receive_packets(private_receiver_t * this)
{
this->logger->log(this->logger, CONTROL, "creating job from packet");
current_job = (job_t *) incoming_packet_job_create(current_packet);
if (current_job == NULL)
{
this->logger->log(this->logger, ERROR, "job creation failed");
}
if (global_job_queue->add(global_job_queue,current_job) != SUCCESS)
{
this->logger->log(this->logger, ERROR, "job queueing failed");
}
global_job_queue->add(global_job_queue,current_job);
}
/* bad bad, rebuild the socket ? */
@@ -103,7 +94,7 @@ static void receive_packets(private_receiver_t * this)
/**
* Implementation of receiver_t's destroy function
*/
static status_t destroy(private_receiver_t *this)
static void destroy(private_receiver_t *this)
{
this->logger->log(this->logger, CONTROL | MORE, "Going to terminate receiver thread");
pthread_cancel(this->assigned_thread);
@@ -114,7 +105,6 @@ static status_t destroy(private_receiver_t *this)
global_logger_manager->destroy_logger(global_logger_manager, this->logger);
allocator_free(this);
return SUCCESS;
}
/*
@@ -124,14 +114,10 @@ receiver_t * receiver_create()
{
private_receiver_t *this = allocator_alloc_thing(private_receiver_t);
this->public.destroy = (status_t(*)(receiver_t*)) destroy;
this->public.destroy = (void(*)(receiver_t*)) destroy;
this->receive_packets = receive_packets;
this->logger = global_logger_manager->create_logger(global_logger_manager, RECEIVER, NULL);
if (this->logger == NULL)
{
allocator_free(this);
}
if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))this->receive_packets, this) != 0)
{
+1 -3
View File
@@ -42,10 +42,8 @@ struct receiver_t {
* @brief Destroys a receiver_t
*
* @param receiver receiver object
* @return
* - SUCCESS in any case
*/
status_t (*destroy) (receiver_t *receiver);
void (*destroy) (receiver_t *receiver);
};
/**
+13 -21
View File
@@ -43,7 +43,6 @@ struct private_scheduler_t {
*/
scheduler_t public;
/**
* @brief Get events from the event queue and add them to to job queue.
*
@@ -53,16 +52,15 @@ struct private_scheduler_t {
*/
void (*get_events) (private_scheduler_t *this);
/**
* Assigned thread to the scheduler_t object
*/
pthread_t assigned_thread;
/**
* logger for this scheduler
*/
logger_t *logger;
/**
* Assigned thread to the scheduler_t object
*/
pthread_t assigned_thread;
/**
* logger for this scheduler
*/
logger_t *logger;
};
/**
@@ -81,7 +79,7 @@ static void get_events(private_scheduler_t * this)
{
this->logger->log(this->logger, CONTROL|MORE, "waiting for next event...");
/* get a job, this block until one is available */
global_event_queue->get(global_event_queue, &current_job);
current_job = global_event_queue->get(global_event_queue);
/* queue the job in the job queue, workers will eat them */
global_job_queue->add(global_job_queue, current_job);
this->logger->log(this->logger, CONTROL, "got event, added job %s to job-queue.",
@@ -92,7 +90,7 @@ static void get_events(private_scheduler_t * this)
/**
* Implementation of scheduler_t's destroy function
*/
static status_t destroy(private_scheduler_t *this)
static void destroy(private_scheduler_t *this)
{
this->logger->log(this->logger, CONTROL | MORE, "Going to terminate scheduler thread");
pthread_cancel(this->assigned_thread);
@@ -103,7 +101,6 @@ static status_t destroy(private_scheduler_t *this)
global_logger_manager->destroy_logger(global_logger_manager, this->logger);
allocator_free(this);
return SUCCESS;
}
@@ -111,20 +108,15 @@ scheduler_t * scheduler_create()
{
private_scheduler_t *this = allocator_alloc_thing(private_scheduler_t);
this->public.destroy = (status_t(*)(scheduler_t*)) destroy;
this->public.destroy = (void(*)(scheduler_t*)) destroy;
this->get_events = get_events;
this->logger = global_logger_manager->create_logger(global_logger_manager, SCHEDULER, NULL);
if (this->logger == NULL)
{
allocator_free(this);
return NULL;
}
if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))this->get_events, this) != 0)
{
/* thread could not be created */
this->logger->log(this->logger, ERROR, "Scheduler thread could not be created!");
this->logger->log(this->logger, ERROR, "Scheduler thread could not be created!");
global_logger_manager->destroy_logger(global_logger_manager, this->logger);
allocator_free(this);
return NULL;
+3 -5
View File
@@ -41,10 +41,8 @@ struct scheduler_t {
* @brief Destroys a scheduler object.
*
* @param scheduler scheduler object
* @return
* - SUCCESS in any case
*/
status_t (*destroy) (scheduler_t *scheduler);
void (*destroy) (scheduler_t *scheduler);
};
/**
@@ -54,8 +52,8 @@ struct scheduler_t {
* and adds them to the job queue.
*
* @return
* - the created scheduler_t instance, or
* - NULL if thread could not be started
* - the created scheduler_t instance, or
* - NULL if thread could not be started
*
* @ingroup threads
*/
+10 -18
View File
@@ -78,24 +78,22 @@ static void send_packets(private_sender_t * this)
while (1)
{
while (global_send_queue->get(global_send_queue,&current_packet) == SUCCESS)
current_packet = global_send_queue->get(global_send_queue);
this->logger->log(this->logger, CONTROL|MORE, "got a packet, sending it");
status = global_socket->send(global_socket,current_packet);
if (status != SUCCESS)
{
this->logger->log(this->logger, CONTROL|MORE, "got a packet, sending it");
status = global_socket->send(global_socket,current_packet);
if (status != SUCCESS)
{
this->logger->log(this->logger, ERROR, "sending failed, socket returned %s",
mapping_find(status_m, status));
}
current_packet->destroy(current_packet);
this->logger->log(this->logger, ERROR, "sending failed, socket returned %s",
mapping_find(status_m, status));
}
current_packet->destroy(current_packet);
}
}
/**
* implements sender_t.destroy
*/
static status_t destroy(private_sender_t *this)
static void destroy(private_sender_t *this)
{
this->logger->log(this->logger, CONTROL | MORE, "Going to terminate sender thread");
pthread_cancel(this->assigned_thread);
@@ -106,7 +104,6 @@ static status_t destroy(private_sender_t *this)
global_logger_manager->destroy_logger(global_logger_manager, this->logger);
allocator_free(this);
return SUCCESS;
}
/*
@@ -117,15 +114,10 @@ sender_t * sender_create()
private_sender_t *this = allocator_alloc_thing(private_sender_t);
this->send_packets = send_packets;
this->public.destroy = (status_t(*)(sender_t*)) destroy;
this->public.destroy = (void(*)(sender_t*)) destroy;
this->logger = global_logger_manager->create_logger(global_logger_manager, SENDER, NULL);
if (this->logger == NULL)
{
allocator_free(this);
return NULL;
}
if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))this->send_packets, this) != 0)
{
this->logger->log(this->logger, ERROR, "Sender thread could not be created");
+1 -3
View File
@@ -38,10 +38,8 @@ struct sender_t {
* @brief Destroys a sender object
*
* @param sender sender object
* @return
* - SUCCESS in any case
*/
status_t (*destroy) (sender_t *sender);
void (*destroy) (sender_t *sender);
};
+20 -48
View File
@@ -81,15 +81,18 @@ struct private_thread_pool_t {
/**
* number of running threads
*/
size_t pool_size;
size_t pool_size;
/**
* array of thread ids
*/
pthread_t *threads;
/**
* logger of the threadpool
*/
logger_t *pool_logger;
/**
* logger of the worker threads
*/
@@ -112,7 +115,7 @@ static void process_jobs(private_thread_pool_t *this)
job_t *job;
job_type_t job_type;
global_job_queue->get(global_job_queue, &job);
job = global_job_queue->get(global_job_queue);
job_type = job->get_type(job);
this->worker_logger->log(this->worker_logger, CONTROL|MORE, "got a job of type %s",
mapping_find(job_type_m,job_type));
@@ -148,15 +151,14 @@ static void process_jobs(private_thread_pool_t *this)
/**
* implementation of private_thread_pool_t.process_incoming_packet_job
*/
void process_incoming_packet_job(private_thread_pool_t *this, incoming_packet_job_t *job)
static void process_incoming_packet_job(private_thread_pool_t *this, incoming_packet_job_t *job)
{
packet_t *packet;
message_t *message;
ike_sa_t *ike_sa;
ike_sa_id_t *ike_sa_id;
status_t status;
if (job->get_packet(job,&packet) != SUCCESS)
{
this->worker_logger->log(this->worker_logger, ERROR, "packet in job could not be retrieved!");
@@ -239,7 +241,7 @@ void process_incoming_packet_job(private_thread_pool_t *this, incoming_packet_jo
/**
* implementation of private_thread_pool_t.process_initiate_ike_sa_job
*/
void process_initiate_ike_sa_job(private_thread_pool_t *this, initiate_ike_sa_job_t *job)
static void process_initiate_ike_sa_job(private_thread_pool_t *this, initiate_ike_sa_job_t *job)
{
/*
* Initiatie an IKE_SA:
@@ -249,19 +251,12 @@ void process_initiate_ike_sa_job(private_thread_pool_t *this, initiate_ike_sa_jo
*/
ike_sa_t *ike_sa;
status_t status;
this->worker_logger->log(this->worker_logger, CONTROL|MOST, "create and checking out IKE SA");
status = global_ike_sa_manager->create_and_checkout(global_ike_sa_manager, &ike_sa);
if (status != SUCCESS)
{
this->worker_logger->log(this->worker_logger, ERROR, "%s by checking out new IKE_SA, job rejected.",
mapping_find(status_m, status));
return;
}
global_ike_sa_manager->create_and_checkout(global_ike_sa_manager, &ike_sa);
this->worker_logger->log(this->worker_logger, CONTROL|MOST, "initializing connection \"%s\"",
job->get_configuration_name(job));
status = ike_sa->initialize_connection(ike_sa, job->get_configuration_name(job));
@@ -272,7 +267,7 @@ void process_initiate_ike_sa_job(private_thread_pool_t *this, initiate_ike_sa_jo
global_ike_sa_manager->checkin_and_delete(global_ike_sa_manager, ike_sa);
return;
}
this->worker_logger->log(this->worker_logger, CONTROL|MOST, "checking in IKE SA");
status = global_ike_sa_manager->checkin(global_ike_sa_manager, ike_sa);
if (status != SUCCESS)
@@ -285,7 +280,7 @@ void process_initiate_ike_sa_job(private_thread_pool_t *this, initiate_ike_sa_jo
/**
* implementation of private_thread_pool_t.process_delete_ike_sa_job
*/
void process_delete_ike_sa_job(private_thread_pool_t *this, delete_ike_sa_job_t *job)
static void process_delete_ike_sa_job(private_thread_pool_t *this, delete_ike_sa_job_t *job)
{
status_t status;
ike_sa_id_t *ike_sa_id = job->get_ike_sa_id(job);
@@ -294,7 +289,7 @@ void process_delete_ike_sa_job(private_thread_pool_t *this, delete_ike_sa_job_t
ike_sa_id->get_initiator_spi(ike_sa_id),
ike_sa_id->get_responder_spi(ike_sa_id),
ike_sa_id->is_initiator(ike_sa_id) ? "initiator" : "responder");
status = global_ike_sa_manager->delete(global_ike_sa_manager, ike_sa_id);
if (status != SUCCESS)
{
@@ -315,7 +310,7 @@ static size_t get_pool_size(private_thread_pool_t *this)
/**
* Implementation of thread_pool_t.destroy
*/
static status_t destroy(private_thread_pool_t *this)
static void destroy(private_thread_pool_t *this)
{
int current;
/* flag thread for termination */
@@ -335,11 +330,8 @@ static status_t destroy(private_thread_pool_t *this)
global_logger_manager->destroy_logger(global_logger_manager, this->worker_logger);
allocator_free(this->threads);
allocator_free(this);
return SUCCESS;
}
#include <stdio.h>
/*
* see header
*/
@@ -348,13 +340,9 @@ thread_pool_t *thread_pool_create(size_t pool_size)
int current;
private_thread_pool_t *this = allocator_alloc_thing(private_thread_pool_t);
if (this == NULL)
{
return NULL;
}
/* fill in public fields */
this->public.destroy = (status_t(*)(thread_pool_t*))destroy;
this->public.destroy = (void(*)(thread_pool_t*))destroy;
this->public.get_pool_size = (size_t(*)(thread_pool_t*))get_pool_size;
this->process_jobs = process_jobs;
@@ -364,26 +352,10 @@ thread_pool_t *thread_pool_create(size_t pool_size)
this->pool_size = pool_size;
this->threads = allocator_alloc(sizeof(pthread_t) * pool_size);
if (this->threads == NULL)
{
allocator_free(this);
return NULL;
}
this->pool_logger = global_logger_manager->create_logger(global_logger_manager,THREAD_POOL,NULL);
if (this->threads == NULL)
{
allocator_free(this);
allocator_free(this->threads);
return NULL;
}
this->worker_logger = global_logger_manager->create_logger(global_logger_manager,WORKER,NULL);
if (this->threads == NULL)
{
global_logger_manager->destroy_logger(global_logger_manager, this->pool_logger);
allocator_free(this);
allocator_free(this->threads);
return NULL;
}
/* try to create as many threads as possible, up tu pool_size */
for (current = 0; current < pool_size; current++)
+1 -3
View File
@@ -52,10 +52,8 @@ struct thread_pool_t {
* sends cancellation request to all threads and AWAITS their termination.
*
* @param thread_pool thread_pool_t object
* @return
* - SUCCESS in any case
*/
status_t (*destroy) (thread_pool_t *thread_pool);
void (*destroy) (thread_pool_t *thread_pool);
};
/**