{"id":23466359,"url":"https://github.com/yuesong-feng/pine","last_synced_at":"2025-04-14T11:43:11.407Z","repository":{"id":39868288,"uuid":"444391486","full_name":"yuesong-feng/pine","owner":"yuesong-feng","description":"A C++ network library for study. ","archived":false,"fork":false,"pushed_at":"2022-12-20T04:15:14.000Z","size":197,"stargazers_count":153,"open_issues_count":4,"forks_count":34,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-28T00:51:16.919Z","etag":null,"topics":["concurrency","cpp","cpp-library","epoll","network","server","socket"],"latest_commit_sha":null,"homepage":"","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/yuesong-feng.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}},"created_at":"2022-01-04T11:20:28.000Z","updated_at":"2025-01-07T12:11:35.000Z","dependencies_parsed_at":"2023-01-29T23:45:44.781Z","dependency_job_id":null,"html_url":"https://github.com/yuesong-feng/pine","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/yuesong-feng%2Fpine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuesong-feng%2Fpine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuesong-feng%2Fpine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuesong-feng%2Fpine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yuesong-feng","download_url":"https://codeload.github.com/yuesong-feng/pine/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248875643,"owners_count":21176100,"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":["concurrency","cpp","cpp-library","epoll","network","server","socket"],"created_at":"2024-12-24T11:56:13.044Z","updated_at":"2025-04-14T11:43:11.378Z","avatar_url":"https://github.com/yuesong-feng.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pine\n\nA high-performance and easy-to-use C++ network library for study.\n\nNow this is just a toy library for education purpose, do not use in production.\n\n## example\n\nAn echo server:\n\n```cpp\n#include \u003ciostream\u003e\n#include \"pine.h\"\n\nint main() {\n  TcpServer *server = new TcpServer();\n\n  Signal::signal(SIGINT, [\u0026] {\n    delete server;\n    std::cout \u003c\u003c \"\\nServer exit!\" \u003c\u003c std::endl;\n    exit(0);\n  });\n\n  server-\u003eonConnect([](Connection *conn) { std::cout \u003c\u003c \"New connection fd: \" \u003c\u003c conn-\u003esocket()-\u003efd() \u003c\u003c std::endl; });\n\n  server-\u003eonRecv([](Connection *conn) {\n    std::cout \u003c\u003c \"Message from client \" \u003c\u003c conn-\u003eread_buf()-\u003ec_str() \u003c\u003c std::endl;\n    conn-\u003eSend(conn-\u003eread_buf()-\u003ec_str());\n  });\n\n  server-\u003eStart();\n\n  delete server;\n  return 0;\n}\n```\n\nAn echo client:\n\n```cpp\n#include \"pine.h\"\n#include \u003ciostream\u003e\n\nint main() {\n  Socket *sock = new Socket();\n  sock-\u003eCreate();\n  sock-\u003eConnect(\"127.0.0.1\", 1234);\n\n  Connection *conn = new Connection(sock-\u003efd(), nullptr);\n\n  while (true) {\n    std::string input;\n    std::getline(std::cin, input);\n    conn-\u003eset_send_buf(input.c_str());\n    conn-\u003eWrite();\n    if (conn-\u003estate() == Connection::State::Closed) {\n      conn-\u003eClose();\n      break;\n    }\n    conn-\u003eRead();\n    std::cout \u003c\u003c \"Message from server: \" \u003c\u003c conn-\u003eread_buf()-\u003ec_str() \u003c\u003c std::endl;\n  }\n\n  delete conn;\n  delete sock;\n  return 0;\n}\n\n```\n\nAn HTTP web server:\n\n## build \u0026 run\nbuild the pine library\n```bash\nmkdir build \u0026\u0026 cd build\ncmake .. # for debug, add -DCMAKE_BUILD_TYPE=DEBUG\n\nmake format      # optional\nmake cpplint      # optional\nmake clang-tidy  # optional\nmake\n```\n\nbuild tests files, at `pine/build`\n```bash\nmake build-tests\n```\n\nNeed to run your own tests? Write your program in \"test/\" directory, eg. server.cpp\n```bash\n# at pine/build\nmake server\n./bin/server\n```\n\nrun the echo server\n```bash\n./bin/echo_server \u0026\n./bin/echo_client\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuesong-feng%2Fpine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyuesong-feng%2Fpine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuesong-feng%2Fpine/lists"}