Project homepage Mailing List  API Docs  Github Mirror 
{"schema":"libjg2-1", "vpath":"/git/", "avatar":"/git/avatar/", "alang":"en-US,en;q\u003d0.5", "gen_ut":1603329532, "reponame":"libwebsockets", "desc":"libwebsockets lightweight C networking library", "owner": { "name": "Andy Green", "email": "", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },"url":"", "f":3, "items": [ {"schema":"libjg2-1", "cid":"9a7f106b7afb8e99c3dbe3b8ba8d90a3", "oid":{ "oid": "ed1e558eedc79a07837db2f0a41eb94197ad23fa", "alias": [ "refs/heads/master"]},"blobname": "minimal-examples/api-tests/api-test-lwsac/main.c", "blob": "/*\n * lws-api-test-lwsac\n *\n * Written in 2010-2019 by Andy Green \\u003e\n *\n * This file is made available under the Creative Commons CC0 1.0\n * Universal Public Domain Dedication.\n */\n\n#include \u003clibwebsockets.h\u003e\n\nstruct mytest {\n\tint payload;\n\t/* notice doesn't have to be at start of struct */\n\tlws_list_ptr list_next;\n\t/* a struct can appear on multiple lists too... */\n};\n\n/* converts a ptr to struct mytest .list_next to a ptr to struct mytest */\n#define list_to_mytest(p) lws_list_ptr_container(p, struct mytest, list_next)\n\nint main(int argc, const char **argv)\n{\n\tint n, logs \u003d LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE, acc;\n\tlws_list_ptr list_head \u003d NULL, iter;\n\tstruct lwsac *lwsac \u003d NULL;\n\tstruct mytest *m;\n\tconst char *p;\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 API selftest: lwsac\u005cn\u0022);\n\n\t/*\n\t * 1) allocate and create 1000 struct mytest in a linked-list\n\t */\n\n\tfor (n \u003d 0; n \u003c 1000; n++) {\n\t\tm \u003d lwsac_use(\u0026lwsac, sizeof(*m), 0);\n\t\tif (!m)\n\t\t\treturn -1;\n\t\tm-\u003epayload \u003d n;\n\n\t\tlws_list_ptr_insert(\u0026list_head, \u0026m-\u003elist_next, NULL);\n\t}\n\n\t/*\n\t * 2) report some debug info about the lwsac state... those 1000\n\t * allocations actually only required 4 mallocs\n\t */\n\n\tlwsac_info(lwsac);\n\n\t/* 3) iterate the list, accumulating the payloads */\n\n\tacc \u003d 0;\n\titer \u003d list_head;\n\twhile (iter) {\n\t\tm \u003d list_to_mytest(iter);\n\t\tacc +\u003d m-\u003epayload;\n\n\t\tlws_list_ptr_advance(iter);\n\t}\n\n\tif (acc !\u003d 499500) {\n\t\tlwsl_err(\u0022%s: FAIL acc %d\u005cn\u0022, __func__, acc);\n\n\t\treturn 1;\n\t}\n\n\t/*\n\t * 4) deallocate everything (lwsac is also set to NULL). It just\n\t * deallocates the 4 mallocs, everything in there is gone accordingly\n\t */\n\n\tlwsac_free(\u0026lwsac);\n\n\tlwsl_user(\u0022Completed: PASS\u005cn\u0022);\n\n\treturn 0;\n}\n","s":{"c":1603227258,"u": 180}} ],"g": 791,"chitpc": 0,"ehitpc": 0,"indexed":0 , "ab": 0, "si": 0, "db":0, "di":0, "sat":0, "lfc": "7d0a"}