github.com/glide-im/glide@v1.6.0/pkg/conn/connection.go (about)

     1  package conn
     2  
     3  import (
     4  	"errors"
     5  )
     6  
     7  var (
     8  	ErrForciblyClosed   = errors.New("connection was forcibly closed")
     9  	ErrClosed           = errors.New("closed")
    10  	ErrConnectionClosed = errors.New("connection closed")
    11  	ErrBadPackage       = errors.New("bad package data")
    12  	ErrReadTimeout      = errors.New("i/o timeout")
    13  )
    14  
    15  type ConnectionInfo struct {
    16  	Ip   string
    17  	Port int
    18  	Addr string
    19  }
    20  
    21  // Connection expression a network keep-alive connection, WebSocket, tcp etc
    22  type Connection interface {
    23  	// Write message to the connection.
    24  	Write(data []byte) error
    25  	// Read message from the connection.
    26  	Read() ([]byte, error)
    27  	// Close the connection.
    28  	Close() error
    29  	// GetConnInfo return the connection info
    30  	GetConnInfo() *ConnectionInfo
    31  }
    32  
    33  // ConnectionProxy expression a binder of Connection.
    34  type ConnectionProxy struct {
    35  	conn Connection
    36  }
    37  
    38  func (c ConnectionProxy) Write(data []byte) error {
    39  	return c.conn.Write(data)
    40  }
    41  
    42  func (c ConnectionProxy) Read() ([]byte, error) {
    43  	return c.conn.Read()
    44  }
    45  
    46  func (c ConnectionProxy) Close() error {
    47  	return c.conn.Close()
    48  }
    49  
    50  func (c ConnectionProxy) GetConnInfo() *ConnectionInfo {
    51  	return c.conn.GetConnInfo()
    52  }