-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreliable_blank_skeleton.c
99 lines (75 loc) · 1.6 KB
/
reliable_blank_skeleton.c
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
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <stddef.h>
#include <assert.h>
#include <poll.h>
#include <errno.h>
#include <time.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/uio.h>
#include <netinet/in.h>
#include "rlib.h"
struct reliable_state {
rel_t *next; /* Linked list for traversing all connections */
rel_t **prev;
conn_t *c; /* This is the connection object */
/* Add your own data fields below this */
};
rel_t *rel_list;
/* Creates a new reliable protocol session, returns NULL on failure.
* ss is always NULL */
rel_t *
rel_create (conn_t *c, const struct sockaddr_storage *ss,
const struct config_common *cc)
{
rel_t *r;
r = xmalloc (sizeof (*r));
memset (r, 0, sizeof (*r));
if (!c) {
c = conn_create (r, ss);
if (!c) {
free (r);
return NULL;
}
}
r->c = c;
r->next = rel_list;
r->prev = &rel_list;
if (rel_list)
rel_list->prev = &r->next;
rel_list = r;
/* Do any other initialization you need here */
return r;
}
void
rel_destroy (rel_t *r)
{
if (r->next)
r->next->prev = r->prev;
*r->prev = r->next;
conn_destroy (r->c);
/* Free any other allocated memory here */
}
void
rel_recvpkt (rel_t *r, packet_t *pkt, size_t n)
{
/* Your logic implementation here */
}
void
rel_read (rel_t *s)
{
/* Your logic implementation here */
}
void
rel_output (rel_t *r)
{
/* Your logic implementation here */
}
void
rel_timer ()
{
/* Retransmit any packets that need to be retransmitted */
}