Project homepage Mailing List  Warmcat.com  API Docs  Github Mirror 
{"schema":"libjg2-1", "vpath":"/git/", "avatar":"/git/avatar/", "alang":"", "gen_ut":1757918506, "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":"aa04c9acd427a258320a3e9491d68226", "oid":{ "oid": "ade91d83455bd6a551fa9b4ad06de75f879d8142", "alias": [ "refs/heads/main"]},"blobname": "plugins/protocol_dumb_increment.c", "blob": "/*\n * ws protocol handler plugin for \u0022dumb increment\u0022\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 * The person who associated a work with this deed has dedicated\n * the work to the public domain by waiving all of his or her rights\n * to the work worldwide under copyright law, including all related\n * and neighboring rights, to the extent allowed by law. You can copy,\n * modify, distribute and perform the work, even for commercial purposes,\n * all without asking permission.\n *\n * These test plugins are intended to be adapted for use in your code, which\n * may be proprietary. So unlike the library itself, they are licensed\n * Public Domain.\n */\n\n#if !defined (LWS_PLUGIN_STATIC)\n#if !defined(LWS_DLL)\n#define LWS_DLL\n#endif\n#if !defined(LWS_INTERNAL)\n#define LWS_INTERNAL\n#endif\n#include \u003clibwebsockets.h\u003e\n#endif\n\n#include \u003cstring.h\u003e\n\n#define DUMB_PERIOD_US 50000\n\nstruct pss__dumb_increment {\n\tint number;\n};\n\nstruct vhd__dumb_increment {\n\tconst unsigned int *options;\n};\n\nstatic int\ncallback_dumb_increment(struct lws *wsi, enum lws_callback_reasons reason,\n\t\t\tvoid *user, void *in, size_t len)\n{\n\tstruct pss__dumb_increment *pss \u003d (struct pss__dumb_increment *)user;\n\tstruct vhd__dumb_increment *vhd \u003d\n\t\t\t\t(struct vhd__dumb_increment *)\n\t\t\t\tlws_protocol_vh_priv_get(lws_get_vhost(wsi),\n\t\t\t\t\t\tlws_get_protocol(wsi));\n\tuint8_t buf[LWS_PRE + 20], *p \u003d \u0026buf[LWS_PRE];\n\tconst struct lws_protocol_vhost_options *opt;\n\tint n, m;\n\n\tswitch (reason) {\n\tcase LWS_CALLBACK_PROTOCOL_INIT:\n\t\tvhd \u003d lws_protocol_vh_priv_zalloc(lws_get_vhost(wsi),\n\t\t\tlws_get_protocol(wsi),\n\t\t\tsizeof(struct vhd__dumb_increment));\n\t\tif (!vhd)\n\t\t\treturn 0;\n\t\tif ((opt \u003d lws_pvo_search(\n\t\t\t\t(const struct lws_protocol_vhost_options *)in,\n\t\t\t\t\u0022options\u0022)))\n\t\t\tvhd-\u003eoptions \u003d (unsigned int *)opt-\u003evalue;\n\t\tbreak;\n\n\tcase LWS_CALLBACK_ESTABLISHED:\n\t\tpss-\u003enumber \u003d 0;\n\t\tif (!vhd-\u003eoptions || !((*vhd-\u003eoptions) \u0026 1))\n\t\t\tlws_set_timer_usecs(wsi, DUMB_PERIOD_US);\n\t\tbreak;\n\n\tcase LWS_CALLBACK_SERVER_WRITEABLE:\n\t\tn \u003d lws_snprintf((char *)p, sizeof(buf) - LWS_PRE, \u0022%d\u0022,\n\t\t\t\t pss-\u003enumber++);\n\t\tm \u003d lws_write(wsi, p, (unsigned int)n, LWS_WRITE_TEXT);\n\t\tif (m \u003c n) {\n\t\t\tlwsl_err(\u0022ERROR %d writing to di socket\u005cn\u0022, n);\n\t\t\treturn -1;\n\t\t}\n\t\tbreak;\n\n\tcase LWS_CALLBACK_RECEIVE:\n\t\tif (len \u003c 6)\n\t\t\tbreak;\n\t\tif (strncmp((const char *)in, \u0022reset\u005cn\u0022, 6) \u003d\u003d 0)\n\t\t\tpss-\u003enumber \u003d 0;\n\t\tif (strncmp((const char *)in, \u0022closeme\u005cn\u0022, 8) \u003d\u003d 0) {\n\t\t\tlwsl_notice(\u0022dumb_inc: closing as requested\u005cn\u0022);\n\t\t\tlws_close_reason(wsi, LWS_CLOSE_STATUS_GOINGAWAY,\n\t\t\t\t\t (unsigned char *)\u0022seeya\u0022, 5);\n\t\t\treturn -1;\n\t\t}\n\t\tbreak;\n\n\tcase LWS_CALLBACK_TIMER:\n\t\tif (!vhd-\u003eoptions || !((*vhd-\u003eoptions) \u0026 1)) {\n\t\t\tlws_callback_on_writable_all_protocol_vhost(\n\t\t\t\tlws_get_vhost(wsi), lws_get_protocol(wsi));\n\t\t\tlws_set_timer_usecs(wsi, DUMB_PERIOD_US);\n\t\t}\n\t\tbreak;\n\n\tdefault:\n\t\tbreak;\n\t}\n\n\treturn 0;\n}\n\n#define LWS_PLUGIN_PROTOCOL_DUMB_INCREMENT \u005c\n\t{ \u005c\n\t\t\u0022dumb-increment-protocol\u0022, \u005c\n\t\tcallback_dumb_increment, \u005c\n\t\tsizeof(struct pss__dumb_increment), \u005c\n\t\t10, /* rx buf size must be \u003e\u003d permessage-deflate rx size */ \u005c\n\t\t0, NULL, 0 \u005c\n\t}\n\n#if !defined (LWS_PLUGIN_STATIC)\n\t\t\nLWS_VISIBLE const struct lws_protocols dumb_increment_protocols[] \u003d {\n\tLWS_PLUGIN_PROTOCOL_DUMB_INCREMENT\n};\n\nLWS_VISIBLE const lws_plugin_protocol_t dumb_increment \u003d {\n\t.hdr \u003d {\n\t\t\u0022dumb increment\u0022,\n\t\t\u0022lws_protocol_plugin\u0022,\n\t\tLWS_BUILD_HASH,\n\t\tLWS_PLUGIN_API_MAGIC\n\t},\n\n\t.protocols \u003d dumb_increment_protocols,\n\t.count_protocols \u003d LWS_ARRAY_SIZE(dumb_increment_protocols),\n\t.extensions \u003d NULL,\n\t.count_extensions \u003d 0,\n};\n\n#endif\n","s":{"c":1757918506,"u": 651}} ],"g": 2135,"chitpc": 0,"ehitpc": 0,"indexed":0 , "ab": 1, "si": 0, "db":0, "di":0, "sat":0, "lfc": "0000"}