mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-16 00:00:07 +01:00

This is a huge patch that should be a global NOP. For unix type platforms it enables -Wconversion to issue warnings (-> error) for all automatic casts that seem less than ideal but are normally concealed by the toolchain. This is things like passing an int to a size_t argument. Once enabled, I went through all args on my default build (which build most things) and tried to make the removed default cast explicit. With that approach it neither change nor bloat the code, since it compiles to whatever it was doing before, just with the casts made explicit... in a few cases I changed some length args from int to size_t but largely left the causes alone. From now on, new code that is relying on less than ideal casting will complain and nudge me to improve it by warnings.
86 lines
1.8 KiB
C
86 lines
1.8 KiB
C
/*
|
|
* lws-minimal-secure-streams-server
|
|
*
|
|
* Written in 2010-2020 by Andy Green <andy@warmcat.com>
|
|
*
|
|
* This file is made available under the Creative Commons CC0 1.0
|
|
* Universal Public Domain Dedication.
|
|
*/
|
|
|
|
#include <libwebsockets.h>
|
|
|
|
extern int interrupted, bad;
|
|
|
|
typedef struct myss {
|
|
struct lws_ss_handle *ss;
|
|
void *opaque_data;
|
|
/* ... application specific state ... */
|
|
lws_sorted_usec_list_t sul;
|
|
|
|
int count;
|
|
} myss_t;
|
|
|
|
/* secure streams payload interface */
|
|
|
|
static lws_ss_state_return_t
|
|
myss_rx(void *userobj, const uint8_t *buf, size_t len, int flags)
|
|
{
|
|
// myss_t *m = (myss_t *)userobj;
|
|
|
|
lwsl_user("%s: len %d, flags: %d\n", __func__, (int)len, flags);
|
|
lwsl_hexdump_info(buf, len);
|
|
|
|
/*
|
|
* If we received the whole message, for our example it means
|
|
* we are done.
|
|
*/
|
|
if (flags & LWSSS_FLAG_EOM) {
|
|
bad = 0;
|
|
interrupted = 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static lws_ss_state_return_t
|
|
myss_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len,
|
|
int *flags)
|
|
{
|
|
//myss_t *m = (myss_t *)userobj;
|
|
|
|
return LWSSSSRET_TX_DONT_SEND; /* don't want to write */
|
|
}
|
|
|
|
static lws_ss_state_return_t
|
|
myss_state(void *userobj, void *sh, lws_ss_constate_t state,
|
|
lws_ss_tx_ordinal_t ack)
|
|
{
|
|
myss_t *m = (myss_t *)userobj;
|
|
|
|
lwsl_user("%s: %p %s, ord 0x%x\n", __func__, m->ss,
|
|
lws_ss_state_name((int)state), (unsigned int)ack);
|
|
|
|
switch (state) {
|
|
case LWSSSCS_CREATING:
|
|
lws_ss_request_tx(m->ss);
|
|
break;
|
|
case LWSSSCS_ALL_RETRIES_FAILED:
|
|
/* if we're out of retries, we want to close the app and FAIL */
|
|
interrupted = 1;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
const lws_ss_info_t ssi_client = {
|
|
.handle_offset = offsetof(myss_t, ss),
|
|
.opaque_user_data_offset = offsetof(myss_t, opaque_data),
|
|
.streamtype = "mintest",
|
|
.rx = myss_rx,
|
|
.tx = myss_tx,
|
|
.state = myss_state,
|
|
.user_alloc = sizeof(myss_t),
|
|
};
|