Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
256dpi committed Dec 6, 2019
1 parent 2c0e77d commit 0bea324
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion transport/base_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
// A Carrier is a generalized stream that can be used with BaseConn.
type Carrier interface {
io.ReadWriteCloser

SetReadDeadline(time.Time) error
}

Expand Down Expand Up @@ -136,6 +135,7 @@ func (c *BaseConn) SetMaxWriteDelay(delay time.Duration) {
}

func (c *BaseConn) resetTimeout() error {
// check timeout
if c.readTimeout > 0 {
return c.carrier.SetReadDeadline(time.Now().Add(c.readTimeout))
}
Expand Down
3 changes: 3 additions & 0 deletions transport/net_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func NewNetServer(listener net.Listener) *NetServer {

// CreateNetServer creates a new TCP server that listens on the provided address.
func CreateNetServer(address string) (*NetServer, error) {
// create listener
listener, err := net.Listen("tcp", address)
if err != nil {
return nil, err
Expand All @@ -29,6 +30,7 @@ func CreateNetServer(address string) (*NetServer, error) {

// CreateSecureNetServer creates a new TLS server that listens on the provided address.
func CreateSecureNetServer(address string, config *tls.Config) (*NetServer, error) {
// create listener
listener, err := tls.Listen("tcp", address, config)
if err != nil {
return nil, err
Expand All @@ -40,6 +42,7 @@ func CreateSecureNetServer(address string, config *tls.Config) (*NetServer, erro
// Accept will return the next available connection or block until a
// connection becomes available, otherwise returns an error.
func (s *NetServer) Accept() (Conn, error) {
// wait next connection
conn, err := s.listener.Accept()
if err != nil {
return nil, err
Expand Down
10 changes: 5 additions & 5 deletions transport/websocket_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,20 @@ func (s *wsStream) Read(buf []byte) (int, error) {
}
}

func (s *wsStream) Write(p []byte) (n int, err error) {
// create writer if missing
func (s *wsStream) Write(buf []byte) (n int, err error) {
// create writer
writer, err := s.conn.NextWriter(websocket.BinaryMessage)
if err != nil {
return 0, err
}

// write packet to writer
n, err = writer.Write(p)
// write buffer
n, err = writer.Write(buf)
if err != nil {
return n, err
}

// close temporary writer
// close writer
err = writer.Close()
if err != nil {
return n, err
Expand Down
2 changes: 2 additions & 0 deletions transport/websocket_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func NewWebSocketServer(listener net.Listener, fallback http.Handler) *WebSocket

// CreateWebSocketServer creates a new WS server that listens on the provided address.
func CreateWebSocketServer(address string, fallback http.Handler) (*WebSocketServer, error) {
// create listener
listener, err := net.Listen("tcp", address)
if err != nil {
return nil, err
Expand All @@ -47,6 +48,7 @@ func CreateWebSocketServer(address string, fallback http.Handler) (*WebSocketSer
// CreateSecureWebSocketServer creates a new WSS server that listens on the
// provided address.
func CreateSecureWebSocketServer(address string, config *tls.Config, fallback http.Handler) (*WebSocketServer, error) {
// create listener
listener, err := tls.Listen("tcp", address, config)
if err != nil {
return nil, err
Expand Down

0 comments on commit 0bea324

Please sign in to comment.