Skip to content

Commit e124d32

Browse files
committed
doc:
1 parent 245ef42 commit e124d32

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import (
3737

3838
type 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

8484
type 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
145145
type 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

218218
1. **状态管理**:使用 `SetSession/GetSession` 存储连接级别的状态
219219
2. **协议解析**:推荐使用无状态解析函数,避免全局共享状态
220-
3. **错误处理**在OnOpen和OnClose中正确处理错误
220+
3. **错误处理**在OnClose中正确处理错误
221221
4. **内存管理**:及时释放大的临时缓冲区,使用连接池复用连接
222222
5. **并发安全**:避免在多个goroutine中同时操作同一个连接
223223

0 commit comments

Comments
 (0)