|
|
@ -46,8 +46,17 @@ struct per_session_data__echo { |
|
|
|
unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + MAX_ECHO_PAYLOAD + LWS_SEND_BUFFER_POST_PADDING]; |
|
|
|
unsigned int len; |
|
|
|
unsigned int index; |
|
|
|
int counter; |
|
|
|
}; |
|
|
|
|
|
|
|
void scramble(unsigned char* str, unsigned int len){ |
|
|
|
unsigned int i = rand() % (len-1); |
|
|
|
unsigned int j = i+1; |
|
|
|
char t = str[i]; |
|
|
|
str[i] = str[j]; |
|
|
|
str[j] = t; |
|
|
|
} |
|
|
|
|
|
|
|
static int |
|
|
|
callback_echo(struct libwebsocket_context *context, |
|
|
|
struct libwebsocket *wsi, |
|
|
@ -58,6 +67,8 @@ callback_echo(struct libwebsocket_context *context, |
|
|
|
|
|
|
|
switch (reason) { |
|
|
|
case LWS_CALLBACK_SERVER_WRITEABLE: |
|
|
|
pss->counter++; |
|
|
|
scramble(&pss->buf[LWS_SEND_BUFFER_PRE_PADDING], pss->len); |
|
|
|
n = libwebsocket_write(wsi, &pss->buf[LWS_SEND_BUFFER_PRE_PADDING], pss->len, LWS_WRITE_TEXT); |
|
|
|
if (n < 0) { |
|
|
|
lwsl_err("ERROR %d writing to socket, hanging up\n", n); |
|
|
@ -101,8 +112,7 @@ static struct libwebsocket_protocols protocols[] = { |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
void sighandler(int sig) |
|
|
|
{ |
|
|
|
void sighandler(int sig){ |
|
|
|
force_exit = 1; |
|
|
|
} |
|
|
|
|
|
|
|