Added one feature
This commit is contained in:
parent
cf821b1af4
commit
735dab01a8
2 changed files with 13 additions and 3 deletions
14
main.cpp
14
main.cpp
|
@ -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 char buf[LWS_SEND_BUFFER_PRE_PADDING + MAX_ECHO_PAYLOAD + LWS_SEND_BUFFER_POST_PADDING];
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
unsigned int index;
|
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
|
static int
|
||||||
callback_echo(struct libwebsocket_context *context,
|
callback_echo(struct libwebsocket_context *context,
|
||||||
struct libwebsocket *wsi,
|
struct libwebsocket *wsi,
|
||||||
|
@ -58,6 +67,8 @@ callback_echo(struct libwebsocket_context *context,
|
||||||
|
|
||||||
switch (reason) {
|
switch (reason) {
|
||||||
case LWS_CALLBACK_SERVER_WRITEABLE:
|
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);
|
n = libwebsocket_write(wsi, &pss->buf[LWS_SEND_BUFFER_PRE_PADDING], pss->len, LWS_WRITE_TEXT);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
lwsl_err("ERROR %d writing to socket, hanging up\n", n);
|
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;
|
force_exit = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
run
2
run
|
@ -3,7 +3,7 @@
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
cd build
|
cd build
|
||||||
cmake ..
|
cmake ..
|
||||||
make -j8
|
make -j8 || exit 1
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
./build/server
|
./build/server
|
||||||
|
|
Reference in a new issue