StartWriter is the goroutine that writes messages to the client (写消息Goroutine, 用户将数据发送给客户端)
()
| 187 | // StartWriter is the goroutine that writes messages to the client |
| 188 | // (写消息Goroutine, 用户将数据发送给客户端) |
| 189 | func (c *KcpConnection) StartWriter() { |
| 190 | zlog.Ins().DebugF("Writer Goroutine is running") |
| 191 | defer zlog.Ins().DebugF("%s [conn Writer exit!]", c.RemoteAddr().String()) |
| 192 | |
| 193 | for { |
| 194 | select { |
| 195 | case data, ok := <-c.msgBuffChan: |
| 196 | if ok { |
| 197 | if err := c.Send(data); err != nil { |
| 198 | zlog.Ins().ErrorF("Send Buff Data error:, %s Conn Writer exit", err) |
| 199 | break |
| 200 | } |
| 201 | |
| 202 | } else { |
| 203 | zlog.Ins().ErrorF("msgBuffChan is Closed") |
| 204 | break |
| 205 | } |
| 206 | case <-c.ctx.Done(): |
| 207 | return |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | // StartReader is a goroutine that reads data from the client |
| 213 | // (读消息Goroutine,用于从客户端中读取数据) |