-
Notifications
You must be signed in to change notification settings - Fork 0
/
wstable.c
91 lines (77 loc) · 1.88 KB
/
wstable.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
#include "wstable.h"
struct WSEntry *createWSEntry()
{
return (struct WSEntry *)malloc(sizeof(struct WSEntry));
}
struct WSTable *CreateWSTable()
{
struct WSTable *table = (struct WSTable *)malloc(sizeof(struct WSTable));
table->wsEntry = listCreate();
table->max_entry = MAX_ENTRY;
return table;
}
list *getEntryList(struct WSTable *table)
{
return table->wsEntry;
}
void createFdofWSEntry(struct WSTable *table, int fd)
{
struct WSEntry *entry = createWSEntry();
entry->fd = fd;
listAddNodeTail(table->wsEntry, entry);
}
void addId2WSEntry(struct WSTable *table, int fd, char *id, int idLen)
{
listNode *ln;
listIter li;
listRewind(getEntryList(table), &li);
while ((ln = listNext(&li)) != NULL) {
struct WSEntry *entry = listNodeValue(ln);
if (entry->fd == fd) {
entry->idLen = idLen;
memcpy(entry->id, id, idLen);
memcpy(entry->wakestr, "ambarella", 9);
entry->wakestr[9] = '\0';
}
}
}
void delWSEntryById(struct WSTable *table, char *id, int idLen)
{
listNode *ln;
listIter li;
listRewind(getEntryList(table), &li);
while ((ln = listNext(&li)) != NULL) {
struct WSEntry *entry = listNodeValue(ln);
if (memcmp(entry->id, id, idLen) == 0) {
listDelNode(table->wsEntry, ln);
}
}
}
struct WSEntry *searchWSEntryById(struct WSTable *table, char* id, int size)
{
struct WSEntry *entry;
listNode *ln;
listIter li;
listRewind(getEntryList(table), &li);
while ((ln = listNext(&li)) != NULL) {
entry = listNodeValue(ln);
if (memcmp(entry->id, id, size) == 0) {
return entry;
}
}
return NULL;
}
int getFDofWSEntryById(struct WSTable *table, char* id, int size)
{
struct WSEntry *entry;
listNode *ln;
listIter li;
listRewind(getEntryList(table), &li);
while ((ln = listNext(&li)) != NULL) {
entry = listNodeValue(ln);
if (memcmp(entry->id, id, size) == 0) {
return entry->fd;
}
}
return -1;
}