summaryrefslogtreecommitdiffstats
path: root/friendfinder/handler.c
blob: 333ba870067c4f3aaf53a5cdcc78d4863ddcfd19 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#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);
}