HY335a-Project
A_multithread_chat_Server_and_chat_client
Main Page
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Macros
chatserver.h
Go to the documentation of this file.
1
#ifndef CHATSERVER_H
2
#define CHATSERVER_H
3
33
#include <stddef.h>
34
typedef
char
boolean
;
35
36
#define TRUE 1
37
#define FALSE 0
38
39
44
#define BACKLOG_SIZE 1000
45
65
typedef
enum
{
66
LOGIN_MSG = 0x1,
67
LOGOUT_MSG = 0x2,
68
TEXT_MSG = 0x3,
69
USERNAME_NOT_EXIST = 0x4,
70
USER_ALREADY_LOGGED = 0x5,
71
USERS_LOGGED_REQUEST = 0x6,
72
USERS_LOGGED_RESPONSE = 0x7,
73
BROADCAST_MSG = 0x8,
74
UKNOWN_MSG_TYPE = 0xFE,
75
GENERAL_ERROR = 0xFF
76
}
msg_type_t
;
77
78
91
typedef
struct
connection
{
92
int
socket_discriptor
;
93
char
*
username
;
94
char
*
ip
;
95
boolean
is_logged_in
;
96
struct
connection
*previous;
97
struct
connection
*next;
98
}
connection_t
;
99
104
typedef
struct
client_thread_params
{
105
connection_t
*
active_connections_list
;
106
connection_t
*
client_connection
;
107
}
client_thread_params_t
;
108
114
typedef
struct
broadcast_invitation_tread_params
{
115
int
port
;
116
char
*
server_ip
;
117
int
refresh_rate
;
118
}
broadcast_invitation_tread_params_t
;
119
120
132
int
create_tcp_server_socket
(
int
port);
133
145
void
*
print_stats_counters_thread
(
void
*refresh_rate);
146
147
159
void
handle_incoming_connections
(
int
server_socket,
connection_t
*connections_list);
160
161
179
void
*
handle_client_connection_thread
(
void
*thread_parameter);
180
191
msg_type_t
get_message_type
(
char
*buffer,
size_t
buf_len);
192
202
int
send_to_client_online_users
(
connection_t
*connections_list,
203
connection_t
*client_connection);
204
219
boolean
handle_login_message
(
connection_t
*connections_list,
220
connection_t
*client_connection,
221
char
*buffer,
222
size_t
buf_len);
223
233
boolean
handle_logout_message
(
connection_t
*connections_list,
connection_t
*client_connection);
234
235
250
int
handle_text_message
(
connection_t
*connections_list,
251
connection_t
*client_connection,
252
char
*buffer,
253
size_t
buf_len);
254
267
int
send_back_error_message
(
connection_t
*client_connection,
268
msg_type_t
error_type,
269
char
*msg_content,
270
size_t
msg_content_len);
271
278
void
*
broadcast_invitation_tread
(
void
*broadcast_params);
279
280
#endif
Generated by
1.8.1