|
|
|
@ -17,7 +17,7 @@ var (
|
|
|
|
|
|
|
|
|
|
// connection is a wrapper for net.Conn over WebSocket connection.
|
|
|
|
|
type connection struct { |
|
|
|
|
wsc *websocket.Conn |
|
|
|
|
conn *websocket.Conn |
|
|
|
|
reader io.Reader |
|
|
|
|
|
|
|
|
|
mergingReader buf.Reader |
|
|
|
@ -26,7 +26,7 @@ type connection struct {
|
|
|
|
|
|
|
|
|
|
func newConnection(conn *websocket.Conn) *connection { |
|
|
|
|
return &connection{ |
|
|
|
|
wsc: conn, |
|
|
|
|
conn: conn, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -59,7 +59,7 @@ func (c *connection) getReader() (io.Reader, error) {
|
|
|
|
|
return c.reader, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_, reader, err := c.wsc.NextReader() |
|
|
|
|
_, reader, err := c.conn.NextReader() |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
@ -69,7 +69,7 @@ func (c *connection) getReader() (io.Reader, error) {
|
|
|
|
|
|
|
|
|
|
// Write implements io.Writer.
|
|
|
|
|
func (c *connection) Write(b []byte) (int, error) { |
|
|
|
|
if err := c.wsc.WriteMessage(websocket.BinaryMessage, b); err != nil { |
|
|
|
|
if err := c.conn.WriteMessage(websocket.BinaryMessage, b); err != nil { |
|
|
|
|
return 0, err |
|
|
|
|
} |
|
|
|
|
return len(b), nil |
|
|
|
@ -83,16 +83,16 @@ func (c *connection) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (c *connection) Close() error { |
|
|
|
|
c.wsc.WriteControl(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""), time.Now().Add(time.Second*5)) |
|
|
|
|
return c.wsc.Close() |
|
|
|
|
c.conn.WriteControl(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""), time.Now().Add(time.Second*5)) |
|
|
|
|
return c.conn.Close() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (c *connection) LocalAddr() net.Addr { |
|
|
|
|
return c.wsc.LocalAddr() |
|
|
|
|
return c.conn.LocalAddr() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (c *connection) RemoteAddr() net.Addr { |
|
|
|
|
return c.wsc.RemoteAddr() |
|
|
|
|
return c.conn.RemoteAddr() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (c *connection) SetDeadline(t time.Time) error { |
|
|
|
@ -103,9 +103,9 @@ func (c *connection) SetDeadline(t time.Time) error {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (c *connection) SetReadDeadline(t time.Time) error { |
|
|
|
|
return c.wsc.SetReadDeadline(t) |
|
|
|
|
return c.conn.SetReadDeadline(t) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (c *connection) SetWriteDeadline(t time.Time) error { |
|
|
|
|
return c.wsc.SetWriteDeadline(t) |
|
|
|
|
return c.conn.SetWriteDeadline(t) |
|
|
|
|
} |
|
|
|
|