mirror of
https://github.com/yudai/gotty.git
synced 2025-12-24 11:20:13 +01:00
Read all payloads from reader at once
Reader might return before finish reading all pending bytes. This might cause event handling to fail randomly. Signed-off-by: Xiaoguang Sun <sunxiaoguang@gmail.com>
This commit is contained in:
parent
a080c85cbc
commit
01668a5425
1 changed files with 3 additions and 2 deletions
|
|
@ -19,7 +19,7 @@ func (wsw *wsWrapper) Write(p []byte) (n int, err error) {
|
|||
|
||||
func (wsw *wsWrapper) Read(p []byte) (n int, err error) {
|
||||
for {
|
||||
msgType, reader, err := wsw.Conn.NextReader()
|
||||
msgType, bytes, err := wsw.Conn.ReadMessage()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
|
@ -28,6 +28,7 @@ func (wsw *wsWrapper) Read(p []byte) (n int, err error) {
|
|||
continue
|
||||
}
|
||||
|
||||
return reader.Read(p)
|
||||
copy(p, bytes)
|
||||
return len(bytes), err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue