{"id":15074396,"url":"https://github.com/mnyoshie/ezgrpc2","last_synced_at":"2025-04-10T18:44:59.000Z","repository":{"id":250483343,"uuid":"834415625","full_name":"mnyoshie/ezgrpc2","owner":"mnyoshie","description":"A single-threaded, non-blocking, asynchronous gRPC server in C.","archived":false,"fork":false,"pushed_at":"2024-11-27T13:26:22.000Z","size":160,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T16:34:53.416Z","etag":null,"topics":["c","grpc","grpc-server"],"latest_commit_sha":null,"homepage":"https://ezgrpc2.readthedocs.io","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mnyoshie.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"publiccode":null,"codemeta":null}},"created_at":"2024-07-27T07:43:44.000Z","updated_at":"2024-12-18T12:26:31.000Z","dependencies_parsed_at":"2025-02-17T20:43:04.633Z","dependency_job_id":null,"html_url":"https://github.com/mnyoshie/ezgrpc2","commit_stats":{"total_commits":20,"total_committers":2,"mean_commits":10.0,"dds":"0.050000000000000044","last_synced_commit":"70bb8c8b921ad55232dcfe510fbd17e11a3d4533"},"previous_names":["mnyoshie/ezgrpc2"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnyoshie%2Fezgrpc2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnyoshie%2Fezgrpc2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnyoshie%2Fezgrpc2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnyoshie%2Fezgrpc2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mnyoshie","download_url":"https://codeload.github.com/mnyoshie/ezgrpc2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248271925,"owners_count":21075800,"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":["c","grpc","grpc-server"],"created_at":"2024-09-25T03:32:47.127Z","updated_at":"2025-04-10T18:44:58.980Z","avatar_url":"https://github.com/mnyoshie.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EZgRPC2\n\nA single threaded, non-blocking, asynchronous, gRPC library in C.\n\nThis library doesn't necessarily makes the implementation of gRPC server easier, in fact,\nit makes it harder.\n\nThis library does not provide a way to serialized message and is not dependent on any serialization\nlibrary such as protobuf or flatbuffers. You would would have to manually write your own to\nserialize, deserialize your own messages.\n\n## SSL/TLS support\n\nTo be determine.\n\n# Architecture\n\nThis architecture was inspired by `poll(2)`, but instead of polling fds and returning events\nsuch as POLLIN, you poll a lists of paths and it gives events of `EVENT_MESSAGE`,\n`EVENT_DATALOSS` and `EVENT_CANCEL` to specific stream ids.\n\nPseudocode:\n\n\n``` \nint main() {\n  int res;\n  const size_t nb_paths = 2;\n  ezgrpc2_path_t paths[nb_paths];\n  struct path_userdata_t path_userdata[nb_paths];\n#ifdef __unix__\n  /* In a real application, user must configure the server\n   * to handle SIGTERM, and make sure to prevent these\n   * signal from propagating through the main threads and\n   * pool threads via pthread_sigmask(SIG_BLOCK, ...) for\n   * the signal handler and pthread_sigmask(SIG_SETMASK, ...)\n   * for the rest. This is skipped.\n   */\n  signal(SIGPIPE, SIG_IGN);\n#endif\n\n\n  /* Tasks for unary requests (single message with end stream) */\n  pthpool_t *unordered_pool = NULL;\n  /* Tasks for streaming requests (multiple messages in a stream).\n   * streaming rpc is generally slower than unary request since\n   * the messages must be ordered and hence can't be parallelize */\n  pthpool_t *ordered_pool = NULL;\n\n  /* be careful not to increase the workers too much or they might start\n   * fighting.\n   */\n  unordered_pool = pthpool_init(2, -1);\n  assert(unordered_pool != NULL);\n\n  /* worker must be one for an ordered execution */\n  ordered_pool = pthpool_init(1, -1);\n  assert(ordered_pool != NULL);\n  ezgrpc2_server_t *server = ezgrpc2_server_init(\"0.0.0.0\", 19009, \"::\", 19009, 16, NULL);\n  assert(server != NULL);\n\n\n  /*-----------------------------.\n  | What services do we provide? |\n  `-----------------------------*/\n\n  paths[0].path = \"/test.yourAPI/whatever_service1\";\n  paths[1].path = \"/test.yourAPI/whatever_service2\";\n  list_init(\u0026paths[0].list_events);\n  list_init(\u0026paths[1].list_events);\n  /* we expect to receive one or more grpc message in a\n   * single stream.\n   * */\n  path_userdata[0].is_unary = 0;\n  path_userdata[0].callback = callback_path0;\n  paths[0].userdata = path_userdata + 0;\n  /* we expect to receive only one grpc message in a\n   * single stream\n   */\n  path_userdata[1].is_unary = 1;\n  path_userdata[1].callback = callback_path1;\n  paths[1].userdata = path_userdata + 1;\n\n\n\n\n\n  //  gRPC allows clients to make concurent requests to a server in\n  //  a single connection by making use of stream ids in HTTP2.\n  //  \n  //  A gRPC request to a server, at it's bare minimum, must have a `path`\n  //  and one or more `grpc message`s.\n  //  \n  //  When a client makes a requests, that request is not necessarily immediately\n  //  executed, instead, the request is added to the queue in the thread pool,\n  //  waiting to be executed among other requests.\n  //  \n  //  When the tasks has been executed, the result is added to the finished\n  //  queue, waiting to be pulled off with, `pthpool_poll()`. After that\n  //  we can then send our results.\n  //  \n  //  So basically, we have a loop of:\n  //  \n  //    1. Get server events. (server poll)\n  //    2. Add tasks to the thread pool. (give the task to thread pool).\n  //    3. Get finish tasks from the thread pool (thread pool poll)\n  //    4. Send the results. (give the result to the client)\n\n\n  while (1) {\n    int is_pool_empty = pthpool_is_empty(unordered_pool) \u0026\u0026\n                        pthpool_is_empty(ordered_pool);\n\n    /* if thread pool is empty, maybe we can give our resources to the cpu\n     * and wait a little longer.\n     */\n    int timeout = is_pool_empty ? 10000 : 10;\n\n#ifdef __unix__\n    // if sigterm flag has been set by the signal handler, break the loop and kill\n    // server.\n\n    /*   .... */\n#endif\n    // step 1. server poll\n    if ((res = ezgrpc2_server_poll(server, paths, nb_paths, timeout)) \u003c 0)\n      break;\n\n    if (res \u003e 0) {\n      // step 2. Give the task to the thread pool\n      handle_events(server, paths, nb_paths, ordered_pool, unordered_pool);\n    }\n    else if (res == 0) {\n      printf(\"no event\\n\");\n      // No server events, let's check the thread pool.\n    }\n    // step 3, 4 Get finish tasks and send results\n    handle_thread_pool(server, ordered_pool);\n    handle_thread_pool(server, unordered_pool);\n  }\n\n  if (res \u003c 0) {\n    printf(\"poll err\\n\");\n  }\n\n\n  ezgrpc2_server_destroy(server);\n  pthpool_destroy(ordered_pool);\n  pthpool_destroy(unordered_pool);\n  return res;\n}\n\n```\n\nsee `https://github.com/mnyoshie/ezgrpc2/blob/master/examples/hello_worldc.c` for a complete\nMWE server.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmnyoshie%2Fezgrpc2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmnyoshie%2Fezgrpc2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmnyoshie%2Fezgrpc2/lists"}