summaryrefslogblamecommitdiffstats
path: root/friendfinder/handler.c
blob: 333ba870067c4f3aaf53a5cdcc78d4863ddcfd19 (plain) (tree)
1
2
3
4
5
6
7
8
9
                    
 
                       

                     
                    
 
                                                     
                                                        
 
                                          
 






                                                                                    
 
                                                        
 

                              

 
                                     
 


                                                                                    
        



                                                             

 
                                   
 




                                                                                
 

                                 

 
                    
 
                                                       



                            
                
 
#include "pthread.h"

#include "msg_sender.h"
#include "sender.h"
#include "receiver.h"
#include "handler.h"

pthread_t msg_thread, sender_thread, receiver_thread;
int msg_start = 0, sender_start = 0, receiver_start = 0;

void init_msg_thread(char *from, char *to)
{
	if (msg_start == 0)
	{
		struct nick *nicknames = (struct nick*) malloc(sizeof(struct nick));
		nicknames->from = from;
		nicknames->to = to;

		pthread_create(&msg_thread, NULL, msg_main_loop, (void*) nicknames);

		printf("HANDLER: msg thread init...\n");

		msg_start = 1;
	}
}

void init_receiver_thread(char *from)
{
	if (receiver_start == 0)
	{
		pthread_create(&receiver_thread, NULL, receiver_main, (void*) from);
	
		printf("HANDLER: receiver thread init...\n");
		
		receiver_start = 1;
	}
}

void init_sender_thread(char *from)
{
	if (sender_start == 0)
	{
		pthread_create(&sender_thread, NULL, sender_main, (void*) from);

		printf("HANDLER: sender thread init...\n");

		sender_start = 1;
	}
}

void close_threads()
{
	printf("HANDLER: all threads are closed...\n");
	
	set_receiver_exit();
	set_sender_exit();
	
	exit(0);
}