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":1569314980, "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", "oid":{ "oid": "65b2e685673663cb8369739f4b0d042162d13cb4", "alias": [ "refs/heads/master"]},"tree": [ { "name": "libev","mode": "16384", "size":0}, { "name": "libevent","mode": "16384", "size":0}, { "name": "libuv","mode": "16384", "size":0}, { "name": "poll","mode": "16384", "size":0}, { "name": "README.md","mode": "33188", "size":4256}, { "name": "private-lib-event-libs.h","mode": "33188", "size":2969}],"s":{"c":1569290263,"u": 643}} ,{"schema":"libjg2-1", "cid":"ae468958278924d3097b62ed41b78426", "oid":{ "oid": "65b2e685673663cb8369739f4b0d042162d13cb4", "alias": [ "refs/heads/master"]},"blobname": "lib/event-libs/README.md", "blob": "## Information for new event lib implementers\n\n### Introduction\n\nBy default lws has built-in support for POSIX poll() as the event loop.\n\nHowever either to get access to epoll() or other platform specific better\npoll waits, or to integrate with existing applications already using a\nspecific event loop, it can be desirable for lws to use another external\nevent library, like libuv, libevent or libev.\n\n### Code placement\n\nThe code specific to the event library should live in `./lib/event-libs/**lib name**`\n\n### Allowing control over enabling event libs\n\nAll event libs should add a cmake define `LWS_WITH_**lib name**` and make its build\ndependent on it in CMakeLists.txt. Export the cmakedefine in `./cmake/lws_config.h.in`\nas well so user builds can understand if the event lib is available in the lws build it is\ntrying to bind to.\n\nIf the event lib is disabled in cmake, nothing in its directory is built or referenced.\n\n### Event loop ops struct\n\nThe event lib support is defined by `struct lws_event_loop_ops` in `lib/event-libs/private-lib-event-libs.h`,\neach event lib support instantiates one of these and fills in the appropriate ops\ncallbacks to perform its job. By convention that lives in\n`./lib/event-libs/**lib name**/**lib_name**.c`.\n\n### Private event lib declarations\n\nTruly private declarations for the event lib can go in the event-libs directory as you like.\nHowever when the declarations must be accessible to other things in lws build, eg,\nthe event lib support adds members to `struct lws` when enabled, they should be in the\nevent lib support directory in a file `private-lib-event-libs-myeventlib.h`.\n\nSearch for \u0022bring in event libs private declarations\u0022 in `./lib/core/private-lib-core.h\nand add your private event lib support file there following the style used for the other\nevent libs, eg,\n\n```\n#if defined(LWS_WITH_LIBUV)\n #include \u0022event-libs/libuv/private-lib-event-libs-libuv.h\u0022\n#endif\n```\n\nIf the event lib support is disabled at cmake, nothing from its private.h should be used anywhere.\n\n### Integrating event lib assets to lws\n\nIf your event lib needs special storage in lws objects, that's no problem. But to keep\nthings sane, there are some rules.\n\n - declare a \u0022container struct\u0022 in your private.h for everything, eg, the libuv event\n lib support need to add its own assets in the perthread struct, it declares in its private.h\n\n```\nstruct lws_pt_eventlibs_libuv {\n\tuv_loop_t *io_loop;\n\tuv_signal_t signals[8];\n\tuv_timer_t timeout_watcher;\n\tuv_timer_t hrtimer;\n\tuv_idle_t idle;\n};\n```\n\n - add your event lib content in one place in the related lws struct, protected by `#if defined(LWS_WITH_**lib name**)`,\n eg, again for LWS_WITH_LIBUV\n\n```\nstruct lws_context_per_thread {\n\n...\n\n#if defined(LWS_WITH_LIBUV)\n\tstruct lws_pt_eventlibs_libuv uv;\n#endif\n\n...\n```\n\n### Adding to lws available event libs list\n\nEdit the NULL-terminated array `available_event_libs` at the top of `./lib/context.c` to include\na pointer to your new event lib support's ops struct, following the style already there.\n\n```\nconst struct lws_event_loop_ops *available_event_libs[] \u003d {\n#if defined(LWS_WITH_POLL)\n\t\u0026event_loop_ops_poll,\n#endif\n#if defined(LWS_WITH_LIBUV)\n\t\u0026event_loop_ops_uv,\n#endif\n...\n```\n\nThis is used to provide a list of avilable configured backends.\n\n### Enabling event lib adoption\n\nYou need to add a `LWS_SERVER_OPTION...` flag as necessary in `./lib/libwebsockets.h`\n`enum lws_context_options`, and follow the existing code in `lws_create_context()`\nto convert the flag into binding your ops struct to the context.\n\n### Implementation of the event lib bindings\n\nStudy eg libuv implementation, using the available ops in the struct lws_event_loop_ops\nas a guide.\n\n### Destruction\n\nEnding the event loop is generally a bit tricky, because if the event loop is internal\nto the lws context, you cannot destroy it while the event loop is running.\n\nDon't add special exports... we tried that, it's a huge mess. The same user code should be able\nwork with any of the event loops including poll.\n\nThe solution we found was hide the different processing necessary for the different cases in\nlws_destroy_context(). To help with that there are ops available at two different places in\nthe context destroy processing.\n\n","s":{"c":1569290263,"u": 192}} ],"g": 396,"chitpc": 0,"ehitpc": 0, "indexed":0 }