@@ -37,7 +37,7 @@ import (
3737
3838type EchoHandler struct {}
3939
40- func (h *EchoHandler ) OnOpen (c *pulse .Conn , err error ) {
40+ func (h *EchoHandler ) OnOpen (c *pulse .Conn ) {
4141 if err != nil {
4242 log.Printf (" 连接失败: %v " , err)
4343 return
@@ -83,7 +83,7 @@ import (
8383
8484type ProtocolHandler struct {}
8585
86- func (h *ProtocolHandler ) OnOpen (c *pulse .Conn , err error ) {
86+ func (h *ProtocolHandler ) OnOpen (c *pulse .Conn ) {
8787 if err != nil {
8888 return
8989 }
@@ -143,7 +143,7 @@ func main() {
143143
144144``` go
145145type Callback [T any] interface {
146- OnOpen (c *Conn, err error ) // 连接建立时调用
146+ OnOpen (c *Conn) // 连接建立时调用
147147 OnData (c *Conn, data T ) // 接收到数据时调用
148148 OnClose (c *Conn, err error ) // 连接关闭时调用
149149}
@@ -217,7 +217,7 @@ wrk -t12 -c400 -d30s --script=lua/echo.lua http://127.0.0.1:8080
217217
2182181 . ** 状态管理** :使用 ` SetSession/GetSession ` 存储连接级别的状态
2192192 . ** 协议解析** :推荐使用无状态解析函数,避免全局共享状态
220- 3 . ** 错误处理** :在OnOpen和OnClose中正确处理错误
220+ 3 . ** 错误处理** :在OnClose中正确处理错误
2212214 . ** 内存管理** :及时释放大的临时缓冲区,使用连接池复用连接
2222225 . ** 并发安全** :避免在多个goroutine中同时操作同一个连接
223223
0 commit comments