File Conn.c changed (mode: 100644) (index 32e40dd..2309f5e) |
... |
... |
static int Conn_ignore(struct Conn *C) |
1709 |
1709 |
return 0; |
return 0; |
1710 |
1710 |
} |
} |
1711 |
1711 |
|
|
1712 |
|
#if 0 |
|
1713 |
1712 |
/* |
/* |
1714 |
1713 |
* Close a connection if it exceeded maximum idle time or got a timeout |
* Close a connection if it exceeded maximum idle time or got a timeout |
1715 |
1714 |
*/ |
*/ |
|
... |
... |
static void Conn_expire(struct Conn *C) |
1746 |
1745 |
} |
} |
1747 |
1746 |
} |
} |
1748 |
1747 |
} |
} |
1749 |
|
#endif |
|
1750 |
1748 |
|
|
1751 |
1749 |
/* |
/* |
1752 |
1750 |
* Set NODELAY on socket |
* Set NODELAY on socket |
|
... |
... |
__hot static struct Conn *Conn_alloc_prepare(struct Conn *C) |
2115 |
2113 |
C->web = NULL; |
C->web = NULL; |
2116 |
2114 |
C->web_req = NULL; |
C->web_req = NULL; |
2117 |
2115 |
|
|
|
2116 |
|
C->wp = NULL; |
|
2117 |
|
|
2118 |
2118 |
Conn_no++; |
Conn_no++; |
2119 |
2119 |
/* Conn_work_to_do will not be incremented here, only in commit! */ |
/* Conn_work_to_do will not be incremented here, only in commit! */ |
2120 |
2120 |
|
|
|
... |
... |
static inline int Conn_dispatch_events(struct Conn_wpool_worker *w, |
2460 |
2460 |
if (unlikely(e[i].data.fd == 1)) { |
if (unlikely(e[i].data.fd == 1)) { |
2461 |
2461 |
/* TODO: we may have another message type! */ |
/* TODO: we may have another message type! */ |
2462 |
2462 |
Log(0, "We have a master signaling. TODO!\n"); |
Log(0, "We have a master signaling. TODO!\n"); |
|
2463 |
|
exit(0); |
2463 |
2464 |
continue; |
continue; |
2464 |
2465 |
} |
} |
2465 |
2466 |
|
|
|
... |
... |
struct Conn *Conn_connect(const int domain, const int type, const char *addr, |
3489 |
3490 |
return X; |
return X; |
3490 |
3491 |
} |
} |
3491 |
3492 |
|
|
3492 |
|
#if 0 |
|
3493 |
3493 |
/* |
/* |
3494 |
3494 |
* Add tokens to connection |
* Add tokens to connection |
3495 |
3495 |
*/ |
*/ |
|
... |
... |
int Conn_band(struct Conn *C, const unsigned int width, |
3546 |
3546 |
|
|
3547 |
3547 |
return 0; |
return 0; |
3548 |
3548 |
} |
} |
3549 |
|
#endif |
|
3550 |
3549 |
|
|
3551 |
3550 |
#if 0 |
#if 0 |
3552 |
3551 |
TODO |
TODO |
|
... |
... |
int Conn_poll(const int timeout) |
3683 |
3682 |
{ |
{ |
3684 |
3683 |
int ret; |
int ret; |
3685 |
3684 |
int timeout2; |
int timeout2; |
|
3685 |
|
unsigned int slot, last; |
|
3686 |
|
struct Conn *C; |
3686 |
3687 |
|
|
3687 |
3688 |
Log(9, "%s timeout=%d Conn_no=%d Conn_work_to_do=%u\n", |
Log(9, "%s timeout=%d Conn_no=%d Conn_work_to_do=%u\n", |
3688 |
3689 |
__func__, timeout, Conn_no, Conn_work_to_do); |
__func__, timeout, Conn_no, Conn_work_to_do); |
|
... |
... |
int Conn_poll(const int timeout) |
3715 |
3716 |
if (unlikely(ret < 0)) |
if (unlikely(ret < 0)) |
3716 |
3717 |
return -1; |
return -1; |
3717 |
3718 |
|
|
3718 |
|
#if 0 |
|
|
3719 |
|
#if 1 |
3719 |
3720 |
Log(9, "Do compacting, expiration and band stuff...\n"); |
Log(9, "Do compacting, expiration and band stuff...\n"); |
3720 |
|
TODO |
|
3721 |
3721 |
slot = 0; |
slot = 0; |
3722 |
3722 |
while (slot < Conn_no) { |
while (slot < Conn_no) { |
3723 |
3723 |
/* |
/* |
|
... |
... |
int Conn_poll(const int timeout) |
3726 |
3726 |
*/ |
*/ |
3727 |
3727 |
last = Conn_no - 1; |
last = Conn_no - 1; |
3728 |
3728 |
|
|
|
3729 |
|
C = &Conns[slot]; |
|
3730 |
|
if (!C) { |
|
3731 |
|
slot++; |
|
3732 |
|
continue; |
|
3733 |
|
} |
|
3734 |
|
|
|
3735 |
|
#if 0 |
3729 |
3736 |
/* Closing connection if it is in error state. */ |
/* Closing connection if it is in error state. */ |
3730 |
3737 |
if (C->error_state > 0) { |
if (C->error_state > 0) { |
3731 |
3738 |
Log(11, "\tSlot=%u in error [%s], move and free it.\n", |
Log(11, "\tSlot=%u in error [%s], move and free it.\n", |
|
... |
... |
int Conn_poll(const int timeout) |
3734 |
3741 |
Conn_free_intern(last); |
Conn_free_intern(last); |
3735 |
3742 |
continue; |
continue; |
3736 |
3743 |
} |
} |
|
3744 |
|
#endif |
3737 |
3745 |
|
|
3738 |
3746 |
/* No commit done yet */ |
/* No commit done yet */ |
3739 |
3747 |
if (C->state == CONN_STATE_EMPTY) { |
if (C->state == CONN_STATE_EMPTY) { |
|
... |
... |
int Conn_poll(const int timeout) |
3749 |
3757 |
} |
} |
3750 |
3758 |
|
|
3751 |
3759 |
/* test if it expired/timeout */ |
/* test if it expired/timeout */ |
3752 |
|
Conn_expire(slot); |
|
|
3760 |
|
Conn_expire(C); |
3753 |
3761 |
|
|
3754 |
3762 |
/* add tokens */ |
/* add tokens */ |
3755 |
|
Conn_band_update(slot); |
|
|
3763 |
|
Conn_band_update(C); |
3756 |
3764 |
|
|
3757 |
3765 |
slot++; |
slot++; |
3758 |
3766 |
} |
} |
File examples/websocket1.c changed (mode: 100644) (index 38bdb13..8a1f5b5) |
... |
... |
static void ws1(struct Conn *C) |
234 |
234 |
} |
} |
235 |
235 |
|
|
236 |
236 |
Log(5, "\tWe already have an established ws connection\n"); |
Log(5, "\tWe already have an established ws connection\n"); |
|
237 |
|
again: |
237 |
238 |
r = Conn_web_ws_parse(&w, C); |
r = Conn_web_ws_parse(&w, C); |
238 |
239 |
if (r == -1) { |
if (r == -1) { |
239 |
240 |
Log(0, "\tProtocol error: %s!\n", Conn_strerror()); |
Log(0, "\tProtocol error: %s!\n", Conn_strerror()); |
|
... |
... |
static void ws1(struct Conn *C) |
262 |
263 |
json_object_put(json); |
json_object_put(json); |
263 |
264 |
|
|
264 |
265 |
Conn_eat(C, w.len); |
Conn_eat(C, w.len); |
|
266 |
|
goto again; |
265 |
267 |
} |
} |
266 |
268 |
|
|
267 |
269 |
int main(void) |
int main(void) |
File examples/websocket1.data/main.js changed (mode: 100644) (index c5b8629..5c6ea44) |
3 |
3 |
// License: LGPLv3+ |
// License: LGPLv3+ |
4 |
4 |
// Copyright: Catalin(ux) M. BOIE |
// Copyright: Catalin(ux) M. BOIE |
5 |
5 |
|
|
6 |
|
// TODO: escape html to avoid injecting scrpts in chat |
|
|
6 |
|
// TODO: escape html to avoid injecting scripts in chat |
7 |
7 |
// TODO: Will the keepalive do its job? Or should I check if I got an answer for |
// TODO: Will the keepalive do its job? Or should I check if I got an answer for |
8 |
8 |
// the keepalive message and re-connect if not received? |
// the keepalive message and re-connect if not received? |
9 |
9 |
|
|
|
... |
... |
function reconnect() |
74 |
74 |
ws.send(JSON.stringify(data)); |
ws.send(JSON.stringify(data)); |
75 |
75 |
|
|
76 |
76 |
// Arm keep-alive timer |
// Arm keep-alive timer |
77 |
|
clearInterval(ka); |
|
78 |
77 |
ka = setInterval(keep_alive, keep_alive_time_ms); |
ka = setInterval(keep_alive, keep_alive_time_ms); |
79 |
78 |
|
|
80 |
79 |
div_status.innerHTML = 'Connected'; |
div_status.innerHTML = 'Connected'; |
|
... |
... |
function reconnect() |
86 |
85 |
div_status.innerHTML = 'Error: ' + ev.reason + '!'; |
div_status.innerHTML = 'Error: ' + ev.reason + '!'; |
87 |
86 |
} |
} |
88 |
87 |
|
|
|
88 |
|
// This is called also when an error occurs |
|
89 |
|
ws.onclose = function(ev) |
|
90 |
|
{ |
|
91 |
|
clearInterval(ka); |
|
92 |
|
|
|
93 |
|
console.log('onclose: [' + ev.reason + '] ' + ev.code); |
|
94 |
|
timer = setInterval(reconnect, reconnect_time_ms); |
|
95 |
|
|
|
96 |
|
div_status.innerHTML = 'Connection closed: [' |
|
97 |
|
+ ev.reason + '] ' + ev.code + '!'; |
|
98 |
|
} |
|
99 |
|
|
89 |
100 |
ws.onmessage = function(ev) |
ws.onmessage = function(ev) |
90 |
101 |
{ |
{ |
91 |
102 |
var j; |
var j; |
|
... |
... |
function reconnect() |
118 |
129 |
ka = setInterval(keep_alive, keep_alive_time_ms); |
ka = setInterval(keep_alive, keep_alive_time_ms); |
119 |
130 |
} |
} |
120 |
131 |
|
|
121 |
|
ws.onclose = function(ev) |
|
122 |
|
{ |
|
123 |
|
console.log('onclose: [' + ev.reason + '] ' + ev.code); |
|
124 |
|
timer = setInterval(reconnect, reconnect_time_ms); |
|
125 |
|
|
|
126 |
|
div_status.innerHTML = 'Connection closed: [' |
|
127 |
|
+ ev.reason + '] ' + ev.code + '!'; |
|
128 |
|
} |
|
129 |
|
|
|
130 |
132 |
//console.log('ws.readyState=' + ws.readyState); |
//console.log('ws.readyState=' + ws.readyState); |
131 |
133 |
} |
} |
132 |
134 |
|
|