mirror of
https://github.com/yudai/gotty.git
synced 2026-01-08 10:38:50 +01:00
Return min length of buffers
Signed-off-by: Xiaoguang Sun <sunxiaoguang@gmail.com>
This commit is contained in:
parent
01668a5425
commit
6522d4b241
1 changed files with 9 additions and 1 deletions
|
|
@ -17,6 +17,14 @@ 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, bytes, err := wsw.Conn.ReadMessage()
|
||||
|
|
@ -29,6 +37,6 @@ func (wsw *wsWrapper) Read(p []byte) (n int, err error) {
|
|||
}
|
||||
|
||||
copy(p, bytes)
|
||||
return len(bytes), err
|
||||
return minInt(len(p), len(bytes)), err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue