mirror of
https://github.com/yudai/gotty.git
synced 2026-01-14 13:38:51 +01:00
Merge 6522d4b241 into a080c85cbc
This commit is contained in:
commit
3b0db1c688
1 changed files with 11 additions and 2 deletions
|
|
@ -17,9 +17,17 @@ func (wsw *wsWrapper) Write(p []byte) (n int, err error) {
|
|||
return writer.Write(p)
|
||||
}
|
||||
|
||||
func minInt(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
} else {
|
||||
return b
|
||||
}
|
||||
}
|
||||
|
||||
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 +36,7 @@ func (wsw *wsWrapper) Read(p []byte) (n int, err error) {
|
|||
continue
|
||||
}
|
||||
|
||||
return reader.Read(p)
|
||||
copy(p, bytes)
|
||||
return minInt(len(p), len(bytes)), err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue