-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnet_include.h
105 lines (95 loc) · 2.5 KB
/
net_include.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <netdb.h>
#include <time.h>
#include <errno.h>
#include <vector.h>
#define PORT 10330
#define MAX_MESS_LEN 4000
//#define WINDOW_SIZE 64
#define MAX_CLIENT_NAME_LENGTH 80
typedef struct
{
int type; //equals 9
int array[6];
} Update_k;
typedef struct
{
int stamp; //also used in read function: server sends mail back: -1 means null; other means there is a mail
int server; //these two can help distinguish emails
int read; //0 for unread and 1 for read, 2 for end of mail list
char sender[80];
char receiver[80];
char subject[80];
char msg[1000];
} Mail;
//update: 1 means normal update, 2 means update_add, 3 means read, 4 means delete, 5 means list, 6 means print
typedef struct
{
int type; //1 means normal update, 2 means update_add, 3 means read, 4 means delete
char client[80];
int operation; //2 add, 3 read, 4 delete
int server_index; //where the operation is from,mail创始人
int server_stamp; //for safety
int server; //开头人
int index; //the position of the update in the list, scan through the lsit and find the one that has specific index, instead of using for loop to traverse
int array[6]; //for safety, during partition
Mail mail;
} Update;
typedef struct dummy_Update_node
{
Update *update;
struct dummy_Update_node *next;
} Update_node;
typedef struct
{
Update_node *head;
Update_node *tail;
int count;
} Update_list;
typedef struct dummy_Mail_node
{
Mail *mail;
struct dummy_Mail_node *next;
} Mail_node;
typedef struct dummy_Mail_list
{
char client_name[MAX_CLIENT_NAME_LENGTH];
Mail_node dummyhead;
Mail_node *tail;
int count;
struct dummy_Mail_list *next;
} Mail_list;
typedef struct
{
Mail_list *head;
Mail_list *tail;
int count;
} Mail_lists;
typedef struct
{
//only from client
int type; //must be 2 for add
char client[80];
int server_index;
Mail mail;
} Update_add;
typedef struct
{
int type; //must be 3 or 4 for read or delete
char client[80];
int server_index; //the server receiving
int server_stamp; //unique identifier for mail
} Update_r_d;
typedef struct
{
int type; //must be 5 for list, 6 for print membership
char client[80];
int server_index;
} Update_l_p;