Project homepage Mailing List  Warmcat.com  API Docs  Github Mirror 
{"schema":"libjg2-1", "vpath":"/git/", "avatar":"/git/avatar/", "alang":"en-US,en;q\u003d0.5", "gen_ut":1571534752, "reponame":"libwebsockets", "desc":"libwebsockets lightweight C networking library", "owner": { "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },"url":"https://libwebsockets.org/repo/libwebsockets", "f":3, "items": [ {"schema":"libjg2-1", "cid":"6df01eccd6c20ba08d1d608ba56a8b45", "oid":{ "oid": "b7a04a67d15efd0f17bf795b8d3648425b604581", "alias": [ "refs/heads/master"]},"blobname": "minimal-examples/ws-client/minimal-ws-client-echo/minimal-ws-client-echo.c", "blob": "/*\n * lws-minimal-ws-client-echo\n *\n * Written in 2010-2019 by Andy Green \u003candy@warmcat.com\u003e\n *\n * This file is made available under the Creative Commons CC0 1.0\n * Universal Public Domain Dedication.\n *\n * This demonstrates a ws client that echoes back what it was sent, in a\n * way compatible with autobahn -m fuzzingserver\n */\n\n#include \u003clibwebsockets.h\u003e\n#include \u003cstring.h\u003e\n#include \u003csignal.h\u003e\n\n#define LWS_PLUGIN_STATIC\n#include \u0022protocol_lws_minimal_client_echo.c\u0022\n\nstatic struct lws_protocols protocols[] \u003d {\n\tLWS_PLUGIN_PROTOCOL_MINIMAL_CLIENT_ECHO,\n\t{ NULL, NULL, 0, 0 } /* terminator */\n};\n\nstatic struct lws_context *context;\nstatic int interrupted, port \u003d 7681, options \u003d 0;\nstatic const char *url \u003d \u0022/\u0022, *ads \u003d \u0022localhost\u0022, *iface \u003d NULL;\n\n/* pass pointers to shared vars to the protocol */\n\nstatic const struct lws_protocol_vhost_options pvo_iface \u003d {\n\tNULL,\n\tNULL,\n\t\u0022iface\u0022,\t\t/* pvo name */\n\t(void *)\u0026iface\t/* pvo value */\n};\n\nstatic const struct lws_protocol_vhost_options pvo_ads \u003d {\n\t\u0026pvo_iface,\n\tNULL,\n\t\u0022ads\u0022,\t\t/* pvo name */\n\t(void *)\u0026ads\t/* pvo value */\n};\n\nstatic const struct lws_protocol_vhost_options pvo_url \u003d {\n\t\u0026pvo_ads,\n\tNULL,\n\t\u0022url\u0022,\t\t/* pvo name */\n\t(void *)\u0026url\t/* pvo value */\n};\n\nstatic const struct lws_protocol_vhost_options pvo_options \u003d {\n\t\u0026pvo_url,\n\tNULL,\n\t\u0022options\u0022,\t\t/* pvo name */\n\t(void *)\u0026options\t/* pvo value */\n};\n\nstatic const struct lws_protocol_vhost_options pvo_port \u003d {\n\t\u0026pvo_options,\n\tNULL,\n\t\u0022port\u0022,\t\t/* pvo name */\n\t(void *)\u0026port\t/* pvo value */\n};\n\nstatic const struct lws_protocol_vhost_options pvo_interrupted \u003d {\n\t\u0026pvo_port,\n\tNULL,\n\t\u0022interrupted\u0022,\t\t/* pvo name */\n\t(void *)\u0026interrupted\t/* pvo value */\n};\n\nstatic const struct lws_protocol_vhost_options pvo \u003d {\n\tNULL,\t\t/* \u0022next\u0022 pvo linked-list */\n\t\u0026pvo_interrupted,\t/* \u0022child\u0022 pvo linked-list */\n\t\u0022lws-minimal-client-echo\u0022,\t/* protocol name we belong to on this vhost */\n\t\u0022\u0022\t\t/* ignored */\n};\nstatic const struct lws_extension extensions[] \u003d {\n\t{\n\t\t\u0022permessage-deflate\u0022,\n\t\tlws_extension_callback_pm_deflate,\n\t\t\u0022permessage-deflate\u0022\n\t\t \u0022; client_no_context_takeover\u0022\n\t\t \u0022; client_max_window_bits\u0022\n\t},\n\t{ NULL, NULL, NULL /* terminator */ }\n};\n\nvoid sigint_handler(int sig)\n{\n\tinterrupted \u003d 1;\n}\n\nint main(int argc, const char **argv)\n{\n\tstruct lws_context_creation_info info;\n\tconst char *p;\n\tint n, logs \u003d LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE\n\t\t\t/* for LLL_ verbosity above NOTICE to be built into lws,\n\t\t\t * lws must have been configured and built with\n\t\t\t * -DCMAKE_BUILD_TYPE\u003dDEBUG instead of \u003dRELEASE */\n\t\t\t/* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */\n\t\t\t/* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */\n\t\t\t/* | LLL_DEBUG */;\n\n\tif ((p \u003d lws_cmdline_option(argc, argv, \u0022-d\u0022)))\n\t\tlogs \u003d atoi(p);\n\n\tlws_set_log_level(logs, NULL);\n\tlwsl_user(\u0022LWS minimal ws client echo + permessage-deflate + multifragment bulk message\u005cn\u0022);\n\tlwsl_user(\u0022 lws-minimal-ws-client-echo [-n (no exts)] [-u url] [-p port] [-o (once)]\u005cn\u0022);\n\n\tif ((p \u003d lws_cmdline_option(argc, argv, \u0022-u\u0022)))\n\t\turl \u003d p;\n\n\tif ((p \u003d lws_cmdline_option(argc, argv, \u0022-p\u0022)))\n\t\tport \u003d atoi(p);\n\n\tif (lws_cmdline_option(argc, argv, \u0022-o\u0022))\n\t\toptions |\u003d 1;\n\n\tif (lws_cmdline_option(argc, argv, \u0022--ssl\u0022))\n\t\toptions |\u003d 2;\n\n\tif ((p \u003d lws_cmdline_option(argc, argv, \u0022-s\u0022)))\n\t\tads \u003d p;\n\n\tif ((p \u003d lws_cmdline_option(argc, argv, \u0022-i\u0022)))\n\t\tiface \u003d p;\n\n\tlwsl_user(\u0022options %d, ads %s\u005cn\u0022, options, ads);\n\n\tmemset(\u0026info, 0, sizeof info); /* otherwise uninitialized garbage */\n\tinfo.port \u003d CONTEXT_PORT_NO_LISTEN;\n\tinfo.protocols \u003d protocols;\n\tinfo.pvo \u003d \u0026pvo;\n\tif (!lws_cmdline_option(argc, argv, \u0022-n\u0022))\n\t\tinfo.extensions \u003d extensions;\n\tinfo.pt_serv_buf_size \u003d 32 * 1024;\n\tinfo.options \u003d LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT |\n\t\t LWS_SERVER_OPTION_VALIDATE_UTF8;\n\t/*\n\t * since we know this lws context is only ever going to be used with\n\t * one client wsis / fds / sockets at a time, let lws know it doesn't\n\t * have to use the default allocations for fd tables up to ulimit -n.\n\t * It will just allocate for 1 internal and 1 (+ 1 http2 nwsi) that we\n\t * will use.\n\t */\n\tinfo.fd_limit_per_thread \u003d 1 + 1 + 1;\n\n\tif (lws_cmdline_option(argc, argv, \u0022--libuv\u0022))\n\t\tinfo.options |\u003d LWS_SERVER_OPTION_LIBUV;\n\telse\n\t\tsignal(SIGINT, sigint_handler);\n\n\tcontext \u003d lws_create_context(\u0026info);\n\tif (!context) {\n\t\tlwsl_err(\u0022lws init failed\u005cn\u0022);\n\t\treturn 1;\n\t}\n\n\twhile (!lws_service(context, 0) \u0026\u0026 !interrupted)\n\t\t;\n\n\tlws_context_destroy(context);\n\n\tn \u003d (options \u0026 1) ? interrupted !\u003d 2 : interrupted \u003d\u003d 3;\n\tlwsl_user(\u0022Completed %d %s\u005cn\u0022, interrupted, !n ? \u0022OK\u0022 : \u0022failed\u0022);\n\n\treturn n;\n}\n","s":{"c":1571305639,"u": 214}} ],"g": 596,"chitpc": 0,"ehitpc": 0, "indexed":0 }