{"id":13413587,"url":"https://github.com/cheng-zhongliang/event","last_synced_at":"2025-03-14T19:32:42.916Z","repository":{"id":65423867,"uuid":"583935180","full_name":"cheng-zhongliang/event","owner":"cheng-zhongliang","description":"Simple I/O event notification library wirtten in Golang","archived":false,"fork":false,"pushed_at":"2023-12-28T02:41:12.000Z","size":560,"stargazers_count":153,"open_issues_count":0,"forks_count":10,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-22T12:00:36.785Z","etag":null,"topics":["epoll","event","go","io","kqueue","libevent","netpoll","network","networking","non-blocking","reactor"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cheng-zhongliang.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,"publiccode":null,"codemeta":null}},"created_at":"2022-12-31T14:32:20.000Z","updated_at":"2024-09-09T06:02:34.000Z","dependencies_parsed_at":"2023-02-16T05:15:27.657Z","dependency_job_id":"b66bad92-597a-4c2e-868d-9ea2563fd72a","html_url":"https://github.com/cheng-zhongliang/event","commit_stats":{"total_commits":343,"total_committers":5,"mean_commits":68.6,"dds":0.5102040816326531,"last_synced_commit":"963def2f37a07854d92197046d17ad3644139d19"},"previous_names":["cheng-zhongliang/event","cheng-zhongliang/unicorn"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheng-zhongliang%2Fevent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheng-zhongliang%2Fevent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheng-zhongliang%2Fevent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheng-zhongliang%2Fevent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cheng-zhongliang","download_url":"https://codeload.github.com/cheng-zhongliang/event/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243635556,"owners_count":20322962,"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","go","io","kqueue","libevent","netpoll","network","networking","non-blocking","reactor"],"created_at":"2024-07-30T20:01:43.885Z","updated_at":"2025-03-14T19:32:42.593Z","avatar_url":"https://github.com/cheng-zhongliang.png","language":"Go","funding_links":[],"categories":["网络","Networking"],"sub_categories":["音译","Transliteration"],"readme":"\u003cp align=\"center\"\u003e\n\u003cimg \n    src=\"logo.png\" \n    width=\"350\" height=\"175\" border=\"0\" alt=\"event\"\u003e\n\u003cbr\u003e\u003cbr\u003e\n\u003ca title=\"Build Status\" target=\"_blank\" href=\"https://github.com/cheng-zhongliang/event/actions?query=workflow\"\u003e\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/cheng-zhongliang/event/go.yml?logo=github-actions\" /\u003e\u003c/a\u003e\n\u003ca title=\"Codecov\" target=\"_blank\" href=\"https://codecov.io/gh/cheng-zhongliang/event\"\u003e\u003cimg src=\"https://img.shields.io/codecov/c/github/cheng-zhongliang/event?logo=codecov\" /\u003e\u003c/a\u003e\n\u003ca title=\"Supported Platforms\" target=\"_blank\" href=\"https://github.com/cheng-zhongliang/event\"\u003e\u003cimg src=\"https://img.shields.io/badge/platform-Linux%20%7C%20FreeBSD%20%7C%20DragonFly%20%7C%20NetBSD%20%7C%20OpenBSD%20%7C%20Darwin-549688?logo=launchpad\" /\u003e\u003c/a\u003e\n\u003ca title=\"Go Report Card\" target=\"_blank\" href=\"https://goreportcard.com/report/github.com/cheng-zhongliang/event\"\u003e\u003cimg src=\"https://goreportcard.com/badge/github.com/cheng-zhongliang/event\" /\u003e\u003c/a\u003e\n\u003ca title=\"Doc for event\" target=\"_blank\" href=\"https://pkg.go.dev/github.com/cheng-zhongliang/event\"\u003e\u003cimg src=\"https://img.shields.io/badge/go.dev-doc-007d9c?logo=read-the-docs\" /\u003e\u003c/a\u003e\n\u003ca title=\"License\" target=\"_blank\" href=\"https://github.com/cheng-zhongliang/event/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/badge/license-BSD--3--Clause-brightgreen\"\u003e\u003c/a\u003e\n\u003ca title=\"Release\" target=\"_blank\" href=\"https://github.com/cheng-zhongliang/event/releases\"\u003e\u003cimg src=\"https://img.shields.io/github/v/release/cheng-zhongliang/event.svg?color=161823\u0026logo=smartthings\" /\u003e\u003c/a\u003e\n\u003ca title=\"Tag\" target=\"_blank\" href=\"https://github.com/cheng-zhongliang/event/tags\"\u003e\u003cimg src=\"https://img.shields.io/github/v/tag/cheng-zhongliang/event?color=%23ff8936\u0026logo=fitbit\" /\u003e\u003c/a\u003e\n\u003ca title=\"Require Go Version\" target=\"_blank\" href=\"https://github.com/cheng-zhongliang/event\"\u003e\u003cimg src=\"https://img.shields.io/badge/go-%3E%3D1.13-30dff3?logo=go\" /\u003e\u003c/a\u003e\n\u003ca title=\"Mentioned in Awesome Go\" target=\"_blank\" href=\"https://github.com/avelino/awesome-go#networking\"\u003e\u003cimg src=\"https://awesome.re/mentioned-badge.svg\" /\u003e\u003c/a\u003e\n\u003ca title=\"Stars\" target=\"_blank\" href=\"https://starchart.cc/cheng-zhongliang/event\"\u003e\u003cimg alt=\"Stars\" src=\"https://img.shields.io/github/stars/cheng-zhongliang/event.svg?style=social\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n`event` is a network I/O event notification library for Go. It uses [epoll](https://en.wikipedia.org/wiki/Epoll) and [kqueue](https://en.wikipedia.org/wiki/Kqueue) to poll I/O events that is fast and low memory usage. It works in a similar manner as [libevent](https://github.com/libevent/libevent).\n\nThe goal of `event` is to provide a `BASIC` tool for building high performance network applications.\n\n*Note: All development is done on a Raspberry Pi 4B.*\n\n## Features\n\n- Supports Read/Write/Timeout events\n- Flexible timer event and ticker event\n- Supports event priority\n- Simple API\n- Low memory usage\n\n## Getting Started\n\n### Installing\n\nTo start using `event`, just run `go get`:\n\n```sh\n$ go get -u github.com/cheng-zhongliang/event\n```\n\n### Event\n\n- `EvRead` fires when the fd is readable.\n- `EvWrite` fires when the fd is writable.\n- `EvTimeout` fires when the timeout expires.\n\nWhen the event is triggered, the callback function will be called.\n\n### Read/Write/Timeout\n\nThese events can be used in combination.\n\n```go\nbase := event.NewBase()\nev := event.New(base, fd, event.EvRead|event.Timeout, callback, arg)\nev.Attach(time.Second)\n```\n\nWhen the fd is readable or timeout expires, this event will be triggered.\n\n### Option\n\nThe event is one-shot by default. If you want to persist, you can set the `EvPersist` option.\n\n```go\nev := event.New(base, fd, event.EvRead|event.EvPersist, callback, arg)\n```\n\n### Timer\n\nThe timer is a one-shot event that will be triggered after the timeout expires.\n\n```go\nbase := event.NewBase()\nev := event.NewTimer(base, callback, arg)\nev.Attach(time.Second)\n```\n\n### Ticker\n\nThe ticker is a repeating event that will be triggered every time the timeout expires.\n\n```go\nbase := event.NewBase()\nev := event.NewTicker(base, callback, arg)\nev.Attach(time.Second)\n```\n\n### Priority\n\nWhen events are triggered together, high priority events will be dispatched first.\n\n```go\nev := event.New(base, fd, event.EvRead, callback, arg)\nev.SetPriority(event.HP)\n```\n\n### Usage\n\nExample echo server that binds to port 1246:\n\n```go\npackage main\n\nimport (\n\t\"syscall\"\n\n\t\"github.com/cheng-zhongliang/event\"\n)\n\nfunc main() {\n\tbase, err := event.NewBase()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfd := socket()\n\tev := event.New(base, fd, event.EvRead|event.EvPersist, accept, base)\n\tif err := ev.Attach(0); err != nil {\n\t\tpanic(err)\n\t}\n\tif err := base.Dispatch(); err != nil \u0026\u0026 err != syscall.EBADF {\n\t\tpanic(err)\n\t}\n\tsyscall.Close(fd)\n}\n\nfunc socket() int {\n\taddr := syscall.SockaddrInet4{Port: 1246, Addr: [4]byte{0, 0, 0, 0}}\n\tfd, err := syscall.Socket(syscall.AF_INET, syscall.SOCK_STREAM, syscall.IPPROTO_TCP)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tif err := syscall.Bind(fd, \u0026addr); err != nil {\n\t\tpanic(err)\n\t}\n\terr = syscall.Listen(fd, syscall.SOMAXCONN)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn fd\n}\n\nfunc accept(fd int, events uint32, arg interface{}) {\n\tbase := arg.(*event.EventBase)\n\tclientFd, _, err := syscall.Accept(fd)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tev := event.New(base, clientFd, event.EvRead|event.EvPersist, echo, nil)\n\tif err := ev.Attach(0); err != nil {\n\t\tpanic(err)\n\t}\n}\n\nfunc echo(fd int, events uint32, arg interface{}) {\n\tbuf := make([]byte, 0xFFF)\n\tn, err := syscall.Read(fd, buf)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tif _, err := syscall.Write(fd, buf[:n]); err != nil {\n\t\tpanic(err)\n\t}\n}\n```\n\nConnect to the echo server:\n\n```sh\n$ telnet localhost 1246\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcheng-zhongliang%2Fevent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcheng-zhongliang%2Fevent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcheng-zhongliang%2Fevent/lists"}