mirror of
https://github.com/cbeuw/Cloak.git
synced 2024-11-03 23:15:18 +00:00
40 lines
645 B
Go
40 lines
645 B
Go
package util
|
|
|
|
import (
|
|
"github.com/gorilla/websocket"
|
|
"time"
|
|
)
|
|
|
|
type WebSocketConn struct {
|
|
*websocket.Conn
|
|
}
|
|
|
|
func (ws *WebSocketConn) Write(data []byte) (int, error) {
|
|
err := ws.WriteMessage(websocket.BinaryMessage, data)
|
|
if err != nil {
|
|
return 0, err
|
|
} else {
|
|
return len(data), nil
|
|
}
|
|
}
|
|
|
|
func (ws *WebSocketConn) Read(buf []byte) (int, error) {
|
|
_, r, err := ws.NextReader()
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return r.Read(buf)
|
|
}
|
|
|
|
func (ws *WebSocketConn) SetDeadline(t time.Time) error {
|
|
err := ws.SetReadDeadline(t)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = ws.SetWriteDeadline(t)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|