forked from cesanta/mongoose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmg_net_if.c
53 lines (46 loc) · 1.37 KB
/
mg_net_if.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
#include "mg_net_if.h"
#include "mg_internal.h"
#include "mg_net_if_socket.h"
extern const struct mg_iface_vtable mg_default_iface_vtable;
const struct mg_iface_vtable *mg_ifaces[] = {
&mg_default_iface_vtable,
};
int mg_num_ifaces = (int) (sizeof(mg_ifaces) / sizeof(mg_ifaces[0]));
struct mg_iface *mg_if_create_iface(const struct mg_iface_vtable *vtable,
struct mg_mgr *mgr) {
struct mg_iface *iface = (struct mg_iface *) MG_CALLOC(1, sizeof(*iface));
iface->mgr = mgr;
iface->data = NULL;
iface->vtable = vtable;
return iface;
}
struct mg_iface *mg_find_iface(struct mg_mgr *mgr,
const struct mg_iface_vtable *vtable,
struct mg_iface *from) {
int i = 0;
if (from != NULL) {
for (i = 0; i < mgr->num_ifaces; i++) {
if (mgr->ifaces[i] == from) {
i++;
break;
}
}
}
for (; i < mgr->num_ifaces; i++) {
if (mgr->ifaces[i]->vtable == vtable) {
return mgr->ifaces[i];
}
}
return NULL;
}
double mg_mgr_min_timer(const struct mg_mgr *mgr) {
double min_timer = 0;
struct mg_connection *nc;
for (nc = mgr->active_connections; nc != NULL; nc = nc->next) {
if (nc->ev_timer_time <= 0) continue;
if (min_timer == 0 || nc->ev_timer_time < min_timer) {
min_timer = nc->ev_timer_time;
}
}
return min_timer;
}