{"id":20806321,"url":"https://github.com/nodesource/nsuv","last_synced_at":"2025-05-07T04:24:20.252Z","repository":{"id":142818694,"uuid":"228695898","full_name":"nodesource/nsuv","owner":"nodesource","description":"C++ wrapper around libuv focused on making callback arg passing safer","archived":false,"fork":false,"pushed_at":"2024-03-04T20:00:42.000Z","size":591,"stargazers_count":22,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-31T06:23:01.908Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nodesource.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-12-17T20:26:40.000Z","updated_at":"2024-12-07T12:03:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"36b64cb4-d08e-42ce-a021-f51c02861ea7","html_url":"https://github.com/nodesource/nsuv","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodesource%2Fnsuv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodesource%2Fnsuv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodesource%2Fnsuv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodesource%2Fnsuv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nodesource","download_url":"https://codeload.github.com/nodesource/nsuv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252811442,"owners_count":21807938,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T19:19:17.563Z","updated_at":"2025-05-07T04:24:20.220Z","avatar_url":"https://github.com/nodesource.png","language":"C++","readme":"# nsuv\nC++ wrapper around libuv focused on making callback arg passing safer. The\ndata passed to the callback does not use the `data` member of the\n`uv_handle_t` or `uv_req_t`. So they can still be used as usual.\n\nYou can [check out our blog post](https://nodesource.com/blog/intro-nsuv/)\nfor additional information.\n\nExample usage:\n```cpp\n// Notice that the second argument of the callback can contain any pointer type,\n// and it'll automatically be checked from the callsite, and give a compiler\n// error if it doesn't match.\n\n#include \"nsuv-inl.h\"\n\nusing namespace nsuv;\n\nns_tcp client;\nns_tcp incoming;\nns_tcp server;\nns_connect\u003cns_tcp\u003e connect_req;\nns_write\u003cns_tcp\u003e write_req;\n\nstatic void alloc_cb(ns_tcp* handle, size_t, uv_buf_t* buf) {\n  static char slab[1024];\n\n  buf-\u003ebase = slab;\n  buf-\u003elen = sizeof(slab);\n}\n\nstatic void read_cb(ns_tcp* handle, ssize_t, const uv_buf_t*) {\n  handle-\u003eclose();\n  client.close();\n  server.close();\n}\n\nstatic void write_cb(ns_write\u003cns_tcp\u003e* req, int) {\n  // Retrieve a reference to the uv_buf_t array and size.\n  uv_buf_t* bufs = req-\u003ebufs();\n  size_t size = req-\u003esize();\n}\n\nstatic void connection_cb(ns_tcp* server, int) {\n  int r;\n  r = incoming.init(server-\u003eget_loop());\n  r = server-\u003eaccept(\u0026incoming);\n  r = incoming.read_start(alloc_cb, read_cb);\n}\n\nstatic void connect_cb(ns_connect\u003cns_tcp\u003e* req, int, char* data) {\n  static char bye_ctr[] = \"BYE\";\n  uv_buf_t buf1 = uv_buf_init(data, strlen(data));\n  uv_buf_t buf2 = uv_buf_init(bye_ctr, strlen(bye_ctr));\n  // Write to the handle attached to this request and pass along data.\n  int r = req-\u003ehandle()-\u003ewrite(\u0026write_req, { buf1, buf2 }, write_cb);\n}\n\nstatic void do_listen() {\n  static char hello_cstr[] = \"HELLO\";\n  struct sockaddr_in addr_in;\n  struct sockaddr* addr;\n  int r;\n\n  r = uv_ip4_addr(\"127.0.0.1\", 9999, \u0026addr_in);\n  addr = reinterpret_cast\u003cstruct sockaddr*\u003e(\u0026addr_in);\n\n  // Server setup.\n  r = server.init(uv_default_loop());\n  r = server.bind(addr, 0);\n  r = server.listen(1, connection_cb);\n\n  // Client connection.\n  r = client.init(uv_default_loop());\n  r = client.connect(\u0026connect_req, addr, connect_cb, hello_cstr);\n\n  uv_run(uv_default_loop(), UV_RUN_DEFAULT);\n}\n```\n\nAdditional usage can be seen in `test/`.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodesource%2Fnsuv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnodesource%2Fnsuv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodesource%2Fnsuv/lists"}