-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
get-ss.c
71 lines (58 loc) · 1.56 KB
/
get-ss.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
/*
* pico-sspc-binance
*
* Written in 2010 - 2021 by Andy Green <[email protected]>
*
* This file is made available under the Creative Commons CC0 1.0
* Universal Public Domain Dedication.
*
* The SS user struct for the "GET" stream... it reads from
* https://libwebsockets.org/index.html every 5s
*/
#include "private.h"
LWS_SS_USER_TYPEDEF
lws_sorted_usec_list_t sul5;
} get_t;
static void
sul_start_get(lws_sorted_usec_list_t *sul)
{
get_t *g = lws_container_of(sul, get_t, sul5);
lws_ss_request_tx(lws_ss_from_user(g));
lws_sul_schedule(lws_ss_cx_from_user(g), 0, sul, sul_start_get,
5 * LWS_US_PER_SEC);
}
static lws_ss_state_return_t
get_rx(void *userobj, const uint8_t *in, size_t len, int flags)
{
get_t *g = (get_t *)userobj;
lwsl_ss_notice(lws_ss_from_user(g), "RX %u, flags 0x%x",
(unsigned int)len, (unsigned int)flags);
if (len) {
lwsl_hexdump_notice(in, 16);
if (len >= 16)
lwsl_hexdump_notice(in + len - 16, 16);
}
return LWSSSSRET_OK;
}
static lws_ss_state_return_t
get_state(void *userobj, void *h_src, lws_ss_constate_t state,
lws_ss_tx_ordinal_t ack)
{
get_t *g = (get_t *)userobj;
lwsl_ss_notice(lws_ss_from_user(g), "%s (%d), ord 0x%x",
lws_ss_state_name((int)state), state, (unsigned int)ack);
switch (state) {
case LWSSSCS_CREATING:
lws_sul_schedule(lws_ss_cx_from_user(g), 0, &g->sul5,
sul_start_get, 5 * LWS_US_PER_SEC);
break;
case LWSSSCS_DESTROYING:
lws_sul_cancel(&g->sul5);
break;
}
return LWSSSSRET_OK;
}
LWS_SS_INFO("mintest-lws", get_t)
.rx = get_rx,
.state = get_state,
};