blob: 34663bad1fae4cf98ee135575aa751c4ed4ae10d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
package net
import (
"time"
"github.com/gorilla/websocket"
)
type wsConn struct {
conn *websocket.Conn
}
func newWSConn(conn *websocket.Conn) *wsConn {
// Bound incoming message size so a client cannot push arbitrarily large
// frames into memory before the session's truncation logic runs.
conn.SetReadLimit(maxLineLength * 4)
return &wsConn{conn: conn}
}
func (w *wsConn) ReadMessage() (string, error) {
_, msg, err := w.conn.ReadMessage()
return string(msg), err
}
func (w *wsConn) Write(b []byte) (int, error) {
err := w.conn.WriteMessage(websocket.TextMessage, b)
return len(b), err
}
// SetWriteDeadline delegates to the underlying websocket connection, which
// supports deadlines natively.
func (w *wsConn) SetWriteDeadline(ts time.Time) error {
return w.conn.SetWriteDeadline(ts)
}
func (w *wsConn) Close() error {
return w.conn.Close()
}
func (w *wsConn) SetEcho(on bool) error {
if on {
return w.conn.WriteMessage(websocket.TextMessage, []byte("\x1b]10;0\x07"))
}
return w.conn.WriteMessage(websocket.TextMessage, []byte("\x1b]10;1\x07"))
}
|