{"id":26826709,"url":"https://github.com/hslam/netpoll","last_synced_at":"2025-04-28T16:49:42.666Z","repository":{"id":57545295,"uuid":"287180289","full_name":"hslam/netpoll","owner":"hslam","description":"Package netpoll implements a network poller based on epoll/kqueue.","archived":false,"fork":false,"pushed_at":"2023-11-14T13:04:04.000Z","size":377,"stargazers_count":55,"open_issues_count":2,"forks_count":14,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-30T11:32:44.105Z","etag":null,"topics":["epoll","event-driven","fast","go","golang","kqueue","net","netpoll","networking","non-blocking","rescheduling","sendfile","splice","unix"],"latest_commit_sha":null,"homepage":"","language":"Go","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/hslam.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}},"created_at":"2020-08-13T04:25:01.000Z","updated_at":"2025-02-16T12:12:04.000Z","dependencies_parsed_at":"2023-11-14T14:26:51.858Z","dependency_job_id":"ea4b7191-9794-4b99-9aa1-1c3db7e2ae79","html_url":"https://github.com/hslam/netpoll","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hslam%2Fnetpoll","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hslam%2Fnetpoll/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hslam%2Fnetpoll/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hslam%2Fnetpoll/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hslam","download_url":"https://codeload.github.com/hslam/netpoll/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251349015,"owners_count":21575381,"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":["epoll","event-driven","fast","go","golang","kqueue","net","netpoll","networking","non-blocking","rescheduling","sendfile","splice","unix"],"created_at":"2025-03-30T11:30:43.553Z","updated_at":"2025-04-28T16:49:42.648Z","avatar_url":"https://github.com/hslam.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# netpoll\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/hslam/netpoll)](https://pkg.go.dev/github.com/hslam/netpoll)\n[![Build Status](https://github.com/hslam/netpoll/workflows/build/badge.svg)](https://github.com/hslam/netpoll/actions)\n[![codecov](https://codecov.io/gh/hslam/netpoll/branch/master/graph/badge.svg)](https://codecov.io/gh/hslam/netpoll)\n[![Go Report Card](https://goreportcard.com/badge/github.com/hslam/netpoll)](https://goreportcard.com/report/github.com/hslam/netpoll)\n[![LICENSE](https://img.shields.io/github/license/hslam/netpoll.svg?style=flat-square)](https://github.com/hslam/netpoll/blob/master/LICENSE)\n\nPackage netpoll implements a network poller based on epoll/kqueue.\n\n## Features\n\n* Epoll/kqueue\n* TCP/UNIX\n* Compatible with the net.Conn interface.\n* Upgrade connection\n* Non-blocking I/O\n* [Splice](https://github.com/hslam/splice \"splice\")/[sendfile](https://github.com/hslam/sendfile \"sendfile\")\n* Rescheduling workers\n\n**Comparison to other packages.**\n\n|Package| [net](https://github.com/golang/go/tree/master/src/net \"net\")| [netpoll](https://github.com/hslam/netpoll \"netpoll\")|[gnet](https://github.com/panjf2000/gnet \"gnet\")|[evio](https://github.com/tidwall/evio \"evio\")|\n|:--:|:--|:--|:--|:--|\n|Low memory usage|No|Yes|Yes|Yes|\n|Non-blocking I/O|No|Yes|Yes|Yes|\n|Splice/sendfile|Yes|Yes|No|No|\n|Rescheduling|Yes|Yes|No|No|\n|Compatible with the net.Conn interface|Yes|Yes|No|No|\n\n## [Benchmark](http://github.com/hslam/netpoll-benchmark \"netpoll-benchmark\")\n\n\u003cimg src=\"https://raw.githubusercontent.com/hslam/netpoll-benchmark/master/netpoll-qps.png\" width = \"400\" height = \"300\" alt=\"mock 0ms\" align=center\u003e\u003cimg src=\"https://raw.githubusercontent.com/hslam/netpoll-benchmark/master/netpoll-mock-time-qps.png\" width = \"400\" height = \"300\" alt=\"mock 1ms\" align=center\u003e\n\n## Get started\n\n### Install\n```\ngo get github.com/hslam/netpoll\n```\n### Import\n```\nimport \"github.com/hslam/netpoll\"\n```\n### Usage\n#### Simple Example\n```go\npackage main\n\nimport \"github.com/hslam/netpoll\"\n\nfunc main() {\n\tvar handler = \u0026netpoll.DataHandler{\n\t\tNoShared:   true,\n\t\tNoCopy:     true,\n\t\tBufferSize: 1024,\n\t\tHandlerFunc: func(req []byte) (res []byte) {\n\t\t\tres = req\n\t\t\treturn\n\t\t},\n\t}\n\tif err := netpoll.ListenAndServe(\"tcp\", \":9999\", handler); err != nil {\n\t\tpanic(err)\n\t}\n}\n```\n\n#### [TLS](http://github.com/hslam/socket \"socket\") Example\n```go\npackage main\n\nimport (\n\t\"crypto/tls\"\n\t\"github.com/hslam/netpoll\"\n\t\"github.com/hslam/socket\"\n\t\"net\"\n)\n\nfunc main() {\n\tvar handler = \u0026netpoll.DataHandler{\n\t\tNoShared:   true,\n\t\tNoCopy:     true,\n\t\tBufferSize: 1024,\n\t\tHandlerFunc: func(req []byte) (res []byte) {\n\t\t\tres = req\n\t\t\treturn\n\t\t},\n\t}\n\thandler.SetUpgrade(func(conn net.Conn) (net.Conn, error) {\n\t\ttlsConn := tls.Server(conn, socket.DefalutTLSConfig())\n\t\tif err := tlsConn.Handshake(); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn tlsConn, nil\n\t})\n\tif err := netpoll.ListenAndServe(\"tcp\", \":9999\", handler); err != nil {\n\t\tpanic(err)\n\t}\n}\n```\n\n#### [Websocket](http://github.com/hslam/websocket \"websocket\") Example\n```go\npackage main\n\nimport (\n\t\"github.com/hslam/netpoll\"\n\t\"github.com/hslam/websocket\"\n\t\"net\"\n)\n\nfunc main() {\n\tvar handler = \u0026netpoll.ConnHandler{}\n\thandler.SetUpgrade(func(conn net.Conn) (netpoll.Context, error) {\n\t\treturn websocket.Upgrade(conn, nil)\n\t})\n\thandler.SetServe(func(context netpoll.Context) error {\n\t\tws := context.(*websocket.Conn)\n\t\tmsg, err := ws.ReadMessage()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\treturn ws.WriteMessage(msg)\n\t})\n\tif err := netpoll.ListenAndServe(\"tcp\", \":9999\", handler); err != nil {\n\t\tpanic(err)\n\t}\n}\n```\n\n\n#### [HTTP](http://github.com/hslam/rum \"rum\") Example\n```go\npackage main\n\nimport (\n\t\"bufio\"\n\t\"github.com/hslam/mux\"\n\t\"github.com/hslam/netpoll\"\n\t\"github.com/hslam/response\"\n\t\"net\"\n\t\"net/http\"\n\t\"sync\"\n)\n\nfunc main() {\n\tm := mux.New()\n\tm.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n\t\tw.Write([]byte(\"Hello World\"))\n\t})\n\tListenAndServe(\":8080\", m)\n}\n\nfunc ListenAndServe(addr string, handler http.Handler) error {\n\tvar h = \u0026netpoll.ConnHandler{}\n\ttype Context struct {\n\t\treader  *bufio.Reader\n\t\trw      *bufio.ReadWriter\n\t\tconn    net.Conn\n\t\tserving sync.Mutex\n\t}\n\th.SetUpgrade(func(conn net.Conn) (netpoll.Context, error) {\n\t\treader := bufio.NewReader(conn)\n\t\trw := bufio.NewReadWriter(reader, bufio.NewWriter(conn))\n\t\treturn \u0026Context{reader: reader, conn: conn, rw: rw}, nil\n\t})\n\th.SetServe(func(context netpoll.Context) error {\n\t\tctx := context.(*Context)\n\t\tctx.serving.Lock()\n\t\treq, err := http.ReadRequest(ctx.reader)\n\t\tif err != nil {\n\t\t\tctx.serving.Unlock()\n\t\t\treturn err\n\t\t}\n\t\tres := response.NewResponse(req, ctx.conn, ctx.rw)\n\t\thandler.ServeHTTP(res, req)\n\t\tres.FinishRequest()\n\t\tctx.serving.Unlock()\n\t\tresponse.FreeResponse(res)\n\t\treturn nil\n\t})\n\treturn netpoll.ListenAndServe(\"tcp\", addr, h)\n}\n```\n\n### License\nThis package is licensed under a MIT license (Copyright (c) 2020 Meng Huang)\n\n\n### Author\nnetpoll was written by Meng Huang.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhslam%2Fnetpoll","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhslam%2Fnetpoll","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhslam%2Fnetpoll/lists"}