Skip to content

Commit

Permalink
perf: enhance efficiency in accessing slices
Browse files Browse the repository at this point in the history
close #4
  • Loading branch information
lanseyujie committed Apr 30, 2024
1 parent ce85522 commit bbf87f1
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions wssh/wssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func requestPty(sess *ssh.Session, cols, rows int) error {
return err
}

func (w *WebSocketShell) Send(ws *websocket.Conn, reader io.Reader) (err error) {
func (w *WebSocketShell) Send(ws *websocket.Conn, reader io.Reader) error {
buf := w.pool.Get().([]byte)
defer func() {
buf = buf[:0]
Expand All @@ -124,14 +124,14 @@ func (w *WebSocketShell) Send(ws *websocket.Conn, reader io.Reader) (err error)

buf = make([]byte, cap(buf))
buf[0] = byte(SESSION)
_, err = reader.Read(buf[1:])
n, err := reader.Read(buf[1:])
if err != nil {
return
return err
}

err = websocket.Message.Send(ws, buf)
err = websocket.Message.Send(ws, buf[:n+1])

return
return err
}

func (w *WebSocketShell) Receive(ws *websocket.Conn, session *ssh.Session, writer io.WriteCloser) (err error) {
Expand Down

0 comments on commit bbf87f1

Please sign in to comment.