Skip to content
Snippets Groups Projects
Commit 36eb70d7 authored by Andy Green's avatar Andy Green
Browse files

additional casts allow test server build as cpp


With these explicit casts that are not needed in C, it's possible to build
the test server using g++ like this, after building and installing the
library.

g++ -DINSTALL_DATADIR=\"/usr/share\" -ocpptest test.cpp -lwebsockets

Add a small documentation to README.coding

Signed-off-by: default avatarAndy Green <andy.green@linaro.org>
parent bd1132f9
Branches
Tags
No related merge requests found
...@@ -136,3 +136,18 @@ appear in the callback for protocol 0 and allow interface code to ...@@ -136,3 +136,18 @@ appear in the callback for protocol 0 and allow interface code to
manage socket descriptors in other poll loops. manage socket descriptors in other poll loops.
Using with in c++ apps
----------------------
The library is ready for use by C++ apps. You can get started quickly by
copying the test server
$ cp test-server/test-server.c test.cpp
and building it in C++ like this
$ g++ -DINSTALL_DATADIR=\"/usr/share\" -ocpptest test.cpp -lwebsockets
INSTALL_DATADIR is only needed because the test server uses it as shipped, if
you remove the references to it in your app you don't need to define it on
the g++ line either.
...@@ -107,7 +107,7 @@ static int callback_http(struct libwebsocket_context *context, ...@@ -107,7 +107,7 @@ static int callback_http(struct libwebsocket_context *context,
case LWS_CALLBACK_HTTP: case LWS_CALLBACK_HTTP:
for (n = 0; n < (sizeof(whitelist) / sizeof(whitelist[0]) - 1); n++) for (n = 0; n < (sizeof(whitelist) / sizeof(whitelist[0]) - 1); n++)
if (in && strcmp(in, whitelist[n].urlpath) == 0) if (in && strcmp((const char *)in, whitelist[n].urlpath) == 0)
break; break;
sprintf(buf, LOCAL_RESOURCE_PATH"%s", whitelist[n].urlpath); sprintf(buf, LOCAL_RESOURCE_PATH"%s", whitelist[n].urlpath);
...@@ -260,7 +260,7 @@ callback_dumb_increment(struct libwebsocket_context *context, ...@@ -260,7 +260,7 @@ callback_dumb_increment(struct libwebsocket_context *context,
unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 512 + unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 512 +
LWS_SEND_BUFFER_POST_PADDING]; LWS_SEND_BUFFER_POST_PADDING];
unsigned char *p = &buf[LWS_SEND_BUFFER_PRE_PADDING]; unsigned char *p = &buf[LWS_SEND_BUFFER_PRE_PADDING];
struct per_session_data__dumb_increment *pss = user; struct per_session_data__dumb_increment *pss = (struct per_session_data__dumb_increment *)user;
switch (reason) { switch (reason) {
...@@ -288,7 +288,7 @@ callback_dumb_increment(struct libwebsocket_context *context, ...@@ -288,7 +288,7 @@ callback_dumb_increment(struct libwebsocket_context *context,
// fprintf(stderr, "rx %d\n", (int)len); // fprintf(stderr, "rx %d\n", (int)len);
if (len < 6) if (len < 6)
break; break;
if (strcmp(in, "reset\n") == 0) if (strcmp((const char *)in, "reset\n") == 0)
pss->number = 0; pss->number = 0;
break; break;
/* /*
...@@ -337,7 +337,7 @@ callback_lws_mirror(struct libwebsocket_context *context, ...@@ -337,7 +337,7 @@ callback_lws_mirror(struct libwebsocket_context *context,
void *user, void *in, size_t len) void *user, void *in, size_t len)
{ {
int n; int n;
struct per_session_data__lws_mirror *pss = user; struct per_session_data__lws_mirror *pss = (struct per_session_data__lws_mirror *)user;
switch (reason) { switch (reason) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment