-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.h
74 lines (59 loc) · 1.18 KB
/
common.h
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef __COMMON_H__
#define __COMMON_H__
#include <bits/stdc++.h>
#include <stddef.h>
#include <stdint.h>
using namespace std;
int send_all(int sockfd, void *buff, size_t len);
int recv_all(int sockfd, void *buff, size_t len);
vector<string> parse_cmd(char *buf);
// Maximum message size
#define MSG_MAXSIZE 1024
// Maximum ID size
#define MAX_ID 10
// Maximum topic length
#define MAX_TOPIC_LEN 50
// Maximum UDP message size
#define MAX_UDP_MSG_SIZE 1551
#define BUFF 1561
// IP length
#define IP_LEN 16
// TCP message types
#define CONNECT 1
#define SUBSCRIBE 2
#define UNSUBSCRIBE 3
#define DISCONNECT 4
// UDP message types
#define INT 0
#define SHORT_REAL 1
#define FLOAT 2
#define STRING 3
// Packet structure
struct chat_packet {
uint16_t len;
uint16_t type;
char source_id[MAX_ID];
char message[MSG_MAXSIZE + 1];
};
// Subscriber structure
struct subscriber_t {
int sockfd;
char *id;
bool online;
uint16_t port;
uint32_t ip;
};
// UDP message structure
struct udp_msg_t {
char topic[50];
char type;
char msg_content[1500];
};
// Message structure
struct message_t {
int len;
char *message;
char ip[IP_LEN];
uint16_t port;
} __attribute__((packed));
#endif