void client_free (Client *client) { if (client == NULL) return; if (client->file) { fflush (client->file); fclose (client->file); client->file = NULL; } oml_free (client->file_name); oml_free (client->downstream_addr); struct header *header = client->headers; while (header) { struct header *next = header->next; header_free (header); header = next; } msg_queue_destroy (client->messages); cbuf_destroy (client->cbuf); pthread_cond_destroy (&client->condvar); pthread_mutex_destroy (&client->mutex); socket_free (client->recv_socket); oml_free (client); }
int main(void) { pthread_t t_put[5] = {0}; pthread_t t_fetch; msg_queue_t* q; void* t_ret; int i; signal(SIGTERM, on_sigterm); signal(SIGINT, on_sigterm); srand(time(NULL)); if(!(q = msg_queue_create(2))) { printf("msg_queue_errno() = %s\n", msg_queue_errno2str(msg_queue_errno())); return(1); } for(i = 0; i < ARRAY_COUNT(t_put); ++ i) { if(pthread_create(&t_put[i], NULL, put_thread, q)) { terminate = 1; break; } } if(!pthread_create(&t_fetch, NULL, fetch_thread, q)) { sleep(15); terminate = 1; pthread_join(t_fetch, &t_ret); } terminate = 1; for(i = 0; t_put[i] && i < ARRAY_COUNT(t_put); ++ i) { pthread_join(t_put[i], &t_ret); } msg_queue_destroy(q); return(0); }