package main

import (
	"time"

	"github.com/gorilla/websocket"
)

type WsConn struct {
	*websocket.Conn
}

func NewWsConn(c *websocket.Conn) *WsConn {
	self := &WsConn{c}

	return self
}

func (self *WsConn) Read(p []byte) (int, error) {
	_, r, err := self.NextReader()
	if nil != err {
		return 0, err
	}

	return r.Read(p)
}

func (self *WsConn) Write(p []byte) (int, error) {
	w, err := self.NextWriter(websocket.BinaryMessage)
	if nil != err {
		return 0, err
	}
	return w.Write(p)
}

func (self *WsConn) SetDeadline(t time.Time) error {
	err := self.SetReadDeadline(t)
	if err != nil {
		return err
	}
	return self.SetWriteDeadline(t)
}
