From aa7a3494c7ed1b53ec4819371ff014f0b917d074 Mon Sep 17 00:00:00 2001 From: Peter Riemenschneider Date: Thu, 23 Nov 2023 11:48:54 +0100 Subject: [PATCH 01/10] initial commit --- README_En.md | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 README_En.md diff --git a/README_En.md b/README_En.md new file mode 100644 index 0000000..c3cd584 --- /dev/null +++ b/README_En.md @@ -0,0 +1,89 @@ +# greatws +// 支持海量连接的websocket库,callback写法 +A websocket library that allegedly can support massive connections, async in nature, supporting callbacks + +//# 特性 +Main Features +// * 支持 epoll/kqueue +* based on epoll/kqueue +//* 低内存占用 +* low memomory usage +//* 高tps +* high transaction (tps transactions per seconds) volume + +//# 暂不支持 +# Still todo +* ssl +* windows +* io-uring + +//# 警告⚠️ +# Warning +// 早期阶段,暂时不建议生产使用 +Early stages, porduction use is not recommended! + +//# 例子-服务端 +# Example Server +```go + +type echoHandler struct{} + +func (e *echoHandler) OnOpen(c *greatws.Conn) { + // fmt.Printf("OnOpen: %p\n", c) +} + +func (e *echoHandler) OnMessage(c *greatws.Conn, op greatws.Opcode, msg []byte) { + if err := c.WriteTimeout(op, msg, 3*time.Second); err != nil { + fmt.Println("write fail:", err) + } + // if err := c.WriteMessage(op, msg); err != nil { + // slog.Error("write fail:", err) + // } +} + +func (e *echoHandler) OnClose(c *greatws.Conn, err error) { + errMsg := "" + if err != nil { + errMsg = err.Error() + } + slog.Error("OnClose:", errMsg) +} + +type handler struct { + m *greatws.MultiEventLoop +} + +func (h *handler) echo(w http.ResponseWriter, r *http.Request) { + c, err := greatws.Upgrade(w, r, + greatws.WithServerReplyPing(), + // greatws.WithServerDecompression(), + greatws.WithServerIgnorePong(), + greatws.WithServerCallback(&echoHandler{}), + // greatws.WithServerEnableUTF8Check(), + greatws.WithServerReadTimeout(5*time.Second), + greatws.WithServerMultiEventLoop(h.m), + ) + if err != nil { + slog.Error("Upgrade fail:", "err", err.Error()) + } + _ = c +} + +func main() { + + var h handler + + h.m = greatws.NewMultiEventLoopMust(greatws.WithEventLoops(0), greatws.WithMaxEventNum(1000), greatws.WithLogLevel(slog.LevelError)) // epoll, kqueue + h.m.Start() + fmt.Printf("apiname:%s\n", h.m.GetApiName()) + + mux := &http.ServeMux{} + mux.HandleFunc("/autobahn", h.echo) + + rawTCP, err := net.Listen("tcp", ":9001") + if err != nil { + fmt.Println("Listen fail:", err) + return + } +} +``` From fd47efffdced7cd1edb3a5e634f30babb28bf44f Mon Sep 17 00:00:00 2001 From: Peter Riemenschneider Date: Thu, 23 Nov 2023 11:52:22 +0100 Subject: [PATCH 02/10] edits to fix typos and formating --- README_En.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/README_En.md b/README_En.md index c3cd584..1b8b467 100644 --- a/README_En.md +++ b/README_En.md @@ -1,28 +1,28 @@ # greatws -// 支持海量连接的websocket库,callback写法 -A websocket library that allegedly can support massive connections, async in nature, supporting callbacks +// 支持海量连接的websocket库,callback写法 +A websocket library that allegedly can support massive connections, async in nature, supporting callbacks -//# 特性 +//# 特性 Main Features -// * 支持 epoll/kqueue -* based on epoll/kqueue -//* 低内存占用 -* low memomory usage -//* 高tps -* high transaction (tps transactions per seconds) volume +// * 支持 epoll/kqueue +* based on epoll/kqueue +//* 低内存占用 +* low memomory usage +//* 高tps +* high transaction (tps transactions per seconds) volume -//# 暂不支持 -# Still todo +//# 暂不支持 +# Still todo * ssl * windows * io-uring -//# 警告⚠️ -# Warning -// 早期阶段,暂时不建议生产使用 -Early stages, porduction use is not recommended! +//# 警告⚠️ +# Warning +// 早期阶段,暂时不建议生产使用 +Early stages, production use is not recommended! -//# 例子-服务端 +//# 例子-服务端 # Example Server ```go From e2b9d37623e99b780725cc7f5b7c7f921edb093a Mon Sep 17 00:00:00 2001 From: Peter Riemenschneider Date: Thu, 23 Nov 2023 11:53:52 +0100 Subject: [PATCH 03/10] more formating --- README_En.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README_En.md b/README_En.md index 1b8b467..0b21c94 100644 --- a/README_En.md +++ b/README_En.md @@ -3,7 +3,7 @@ A websocket library that allegedly can support massive connections, async in nature, supporting callbacks //# 特性 -Main Features +# Main Features // * 支持 epoll/kqueue * based on epoll/kqueue //* 低内存占用 From fde3603e9388e6d025a29d147df8dc72b955b991 Mon Sep 17 00:00:00 2001 From: Peter Riemenschneider Date: Thu, 23 Nov 2023 11:55:48 +0100 Subject: [PATCH 04/10] more formating --- README_En.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README_En.md b/README_En.md index 0b21c94..8bf31b6 100644 --- a/README_En.md +++ b/README_En.md @@ -4,11 +4,11 @@ A websocket library that allegedly can support massive connections, async in nat //# 特性 # Main Features -// * 支持 epoll/kqueue +//* 支持 epoll/kqueue * based on epoll/kqueue -//* 低内存占用 +//* 低内存占用 * low memomory usage -//* 高tps +//* 高tps * high transaction (tps transactions per seconds) volume //# 暂不支持 From e11cc6da4654a0140607178d0d3a00ea08ca8cba Mon Sep 17 00:00:00 2001 From: Peter Riemenschneider Date: Thu, 23 Nov 2023 11:58:23 +0100 Subject: [PATCH 05/10] more formating --- README_En.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README_En.md b/README_En.md index 8bf31b6..1878f19 100644 --- a/README_En.md +++ b/README_En.md @@ -1,18 +1,18 @@ # greatws -// 支持海量连接的websocket库,callback写法 A websocket library that allegedly can support massive connections, async in nature, supporting callbacks +// 支持海量连接的websocket库,callback写法 -//# 特性 # Main Features -//* 支持 epoll/kqueue -* based on epoll/kqueue -//* 低内存占用 -* low memomory usage -//* 高tps -* high transaction (tps transactions per seconds) volume +//# 特性 +* based on epoll/kqueue +//* 支持 epoll/kqueue +* low memomory usage +//* 低内存占用 +* high transaction (tps transactions per seconds) volume +//* 高tps -//# 暂不支持 # Still todo +//# 暂不支持 * ssl * windows * io-uring From 31a71e25121563e424c3552bd0c37ae5f95f0349 Mon Sep 17 00:00:00 2001 From: Peter Riemenschneider Date: Thu, 23 Nov 2023 11:59:11 +0100 Subject: [PATCH 06/10] more formating --- README_En.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README_En.md b/README_En.md index 1878f19..167d4df 100644 --- a/README_En.md +++ b/README_En.md @@ -4,11 +4,11 @@ A websocket library that allegedly can support massive connections, async in nat # Main Features //# 特性 -* based on epoll/kqueue +* based on epoll/kqueue //* 支持 epoll/kqueue -* low memomory usage +* low memomory usage //* 低内存占用 -* high transaction (tps transactions per seconds) volume +* high transaction (tps transactions per seconds) volume //* 高tps # Still todo From 3b09788d46e7933b190e48ecb22c1913fcf5e11f Mon Sep 17 00:00:00 2001 From: Peter Riemenschneider Date: Thu, 23 Nov 2023 12:00:08 +0100 Subject: [PATCH 07/10] more formating --- README_En.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README_En.md b/README_En.md index 167d4df..5bfe109 100644 --- a/README_En.md +++ b/README_En.md @@ -17,13 +17,13 @@ A websocket library that allegedly can support massive connections, async in nat * windows * io-uring -//# 警告⚠️ # Warning +//# 警告⚠️ +Early stages, production use is not recommended! // 早期阶段,暂时不建议生产使用 -Early stages, production use is not recommended! -//# 例子-服务端 # Example Server +//# 例子-服务端 ```go type echoHandler struct{} From 6414a14114a51f17c3f30dad69fd4184e3591b3d Mon Sep 17 00:00:00 2001 From: Peter Riemenschneider Date: Thu, 23 Nov 2023 12:26:36 +0100 Subject: [PATCH 08/10] added reference of source --- README_En.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README_En.md b/README_En.md index 5bfe109..2cee188 100644 --- a/README_En.md +++ b/README_En.md @@ -1,5 +1,6 @@ # greatws A websocket library that allegedly can support massive connections, async in nature, supporting callbacks +A fork from https://github.com/antlabs/greatws // 支持海量连接的websocket库,callback写法 # Main Features From 27244edb1b21c20170756b6ef6d2bdafdd3d330f Mon Sep 17 00:00:00 2001 From: Peter Riemenschneider Date: Thu, 23 Nov 2023 12:28:20 +0100 Subject: [PATCH 09/10] fixed type --- README_En.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README_En.md b/README_En.md index 2cee188..af3a99c 100644 --- a/README_En.md +++ b/README_En.md @@ -7,7 +7,7 @@ A fork from https://github.com/antlabs/greatws //# 特性 * based on epoll/kqueue //* 支持 epoll/kqueue -* low memomory usage +* low memory usage //* 低内存占用 * high transaction (tps transactions per seconds) volume //* 高tps From bba7fa62b55ea76828f845d5968d8814badbd676 Mon Sep 17 00:00:00 2001 From: Peter Riemenschneider Date: Thu, 23 Nov 2023 12:33:41 +0100 Subject: [PATCH 10/10] change reference --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 9285c2c..25785d9 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/antlabs/greatws +module github.com/prr123/greatws go 1.21