{"id":36488301,"url":"https://github.com/rocket049/connpool","last_synced_at":"2026-01-12T01:53:27.401Z","repository":{"id":57514538,"uuid":"191860820","full_name":"rocket049/connpool","owner":"rocket049","description":"connection pool. 一个连接池，用法参考connpool_test.go","archived":false,"fork":false,"pushed_at":"2019-06-17T02:44:07.000Z","size":18,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-06-20T17:42:34.756Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://gitee.com/rocket049/connpool","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rocket049.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}},"created_at":"2019-06-14T02:08:46.000Z","updated_at":"2024-05-30T09:15:43.000Z","dependencies_parsed_at":"2022-09-06T04:00:21.317Z","dependency_job_id":null,"html_url":"https://github.com/rocket049/connpool","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/rocket049/connpool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocket049%2Fconnpool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocket049%2Fconnpool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocket049%2Fconnpool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocket049%2Fconnpool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rocket049","download_url":"https://codeload.github.com/rocket049/connpool/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocket049%2Fconnpool/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28331268,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T00:36:25.062Z","status":"ssl_error","status_checked_at":"2026-01-12T00:36:15.229Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":"2026-01-12T01:53:27.325Z","updated_at":"2026-01-12T01:53:27.386Z","avatar_url":"https://github.com/rocket049.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# connpool\n\n#### 介绍\n一个TCP连接池，用法参考connpool_test.go\n\n#### 软件架构\n```\ntype Conn\n    func (s *Conn) Close() error\n    func (s *Conn) Read(p []byte) (int, error)\n    func (s *Conn) Timeout() bool\n    func (s *Conn) Write(p []byte) (int, error)\ntype Pool\n    func NewPool(max, timeout int, factory func() (net.Conn, error)) *Pool\n    func (s *Pool) Close()\n    func (s *Pool) Get() (*Conn, error)\n    func (s *Pool) Put(conn1 *Conn)\n\ntype Conn\n\tConn - Wrap of net.Conn\n\n\ttype Conn struct {\n\t    // contains filtered or unexported fields\n\t}\n\nfunc (s *Conn) Close() error\n\tClose - Close the connection\n\n\nfunc (s *Conn) Read(p []byte) (int, error)\n\tRead - Compatible io.Reader\n\nfunc (s *Conn) Timeout() bool\n\tTimeout - Test the connection is timeout. return true/false.\n\nfunc (s *Conn) Write(p []byte) (int, error)\n\tWrite - Compatible io.Write\n\ntype Pool\n\tPool - Please create Pool with function NewPool\n\n\ttype Pool struct {\n\t    // contains filtered or unexported fields\n\t}\n\nfunc NewPool(max, timeout int, factory func() (net.Conn, error)) *Pool\n\tNewPool - Create a new Pool struct,and initialize it.\n\n\tmax - the max connection number.\n\ttimeout - the program will use it to set deadline value.\n\tfactory - wrap of net.Dial(...).\n\nfunc (s *Pool) Close()\n\tClose - Close all connections in this Pool\n\nfunc (s *Pool) Get() (*Conn, error)\n\tGet - Get a new connection from the Pool\n\nfunc (s *Pool) Put(conn1 *Conn)\n\tPut - Put a connection back to the Pool\n```\n\n#### 安装教程\n\ngo get -v -u github.com/rocket049/connpool\n\n或：\n\ngo get -v -u gitee.com/rocket049/connpool\n\n#### 使用说明\n\n```\nimport \"github.com/rocket049/connpool\"\n//import \"gitee.com/rocket049/connpool\"\n\nfunc factory() (net.Conn,error) {\n\treturn net.Dial(\"tcp\",\"127.0.0.1:7060\")\n}\n\nfunc UsePool() {\n\tpool1 := connpool.NewPool(10, 30 ,factory)\n\tdefer pool1.Close()\n\tvar wg sync.WaitGroup\n\tfor i:=0;i\u003c50;i++ {\n\t\twg.Add(1)\n\t\tgo func(n int){\n\t\t    // connect\n\t\t\tconn ,err := pool1.Get()\n\t\t\tif err!=nil {\n\t\t\t\t...\n\t\t\t}\n\t\t\t//send\n\t\t\t_,err = conn.Write( msg )\n\t\t\tif err!=nil{\n\t\t\t\t...\n\t\t\t}\n\t\t\t//recv\n\t\t\tn1,err := conn.Read( buf )\n\t\t\tif err!=nil{\n\t\t\t\t...\n\t\t\t}\n\t\t\t//timeout\n\t\t\tif conn.Timeout() {\n\t\t\t\tpool1.Put(conn)\n\t\t\t\tconn ,err := pool1.Get()\n\t\t\t\t...\n\t\t\t}\n\t\t\t//close\n\t\t\tpool1.Put(conn)\n\t\t\twg.Done()\n\t\t}(i)\n\t}\n\twg.Wait()\n\n}\n```\n\n#### 参与贡献\n\n1. Fork 本仓库\n2. 新建 Feat_xxx 分支\n3. 提交代码\n4. 新建 Pull Request\n\n\n#### 码云特技\n\n1. 使用 Readme\\_XXX.md 来支持不同的语言，例如 Readme\\_en.md, Readme\\_zh.md\n2. 码云官方博客 [blog.gitee.com](https://blog.gitee.com)\n3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解码云上的优秀开源项目\n4. [GVP](https://gitee.com/gvp) 全称是码云最有价值开源项目，是码云综合评定出的优秀开源项目\n5. 码云官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)\n6. 码云封面人物是一档用来展示码云会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frocket049%2Fconnpool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frocket049%2Fconnpool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frocket049%2Fconnpool/lists"}