2 * libwebsockets-test-server - libwebsockets test implementation
4 * Copyright (C) 2010-2015 Andy Green <andy@warmcat.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation:
9 * version 2.1 of the License.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 #include "test-server.h"
23 /* dumb_increment protocol */
26 callback_dumb_increment(struct libwebsocket_context *context,
27 struct libwebsocket *wsi,
28 enum libwebsocket_callback_reasons reason,
29 void *user, void *in, size_t len)
31 unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 512 +
32 LWS_SEND_BUFFER_POST_PADDING];
33 struct per_session_data__dumb_increment *pss =
34 (struct per_session_data__dumb_increment *)user;
35 unsigned char *p = &buf[LWS_SEND_BUFFER_PRE_PADDING];
40 case LWS_CALLBACK_ESTABLISHED:
44 case LWS_CALLBACK_SERVER_WRITEABLE:
45 n = sprintf((char *)p, "%d", pss->number++);
46 m = libwebsocket_write(wsi, p, n, LWS_WRITE_TEXT);
48 lwsl_err("ERROR %d writing to di socket\n", n);
51 if (close_testing && pss->number == 50) {
52 lwsl_info("close tesing limit, closing\n");
57 case LWS_CALLBACK_RECEIVE:
60 if (strcmp((const char *)in, "reset\n") == 0)
64 * this just demonstrates how to use the protocol filter. If you won't
65 * study and reject connections based on header content, you don't need
66 * to handle this callback
68 case LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION:
69 dump_handshake_info(wsi);
70 /* you could return non-zero here and kill the connection */