github.com/nyan233/littlerpc@v0.4.6-0.20230316182519-0c8d5c48abaf/core/common/transport/nilconn.go (about)

     1  package transport
     2  
     3  import (
     4  	"net"
     5  	"time"
     6  )
     7  
     8  // NilConn 提供一个空连接的实现方便测试
     9  type NilConn struct {
    10  	source interface{}
    11  }
    12  
    13  func (nc *NilConn) Close() error {
    14  	return nil
    15  }
    16  
    17  func (nc *NilConn) Read(b []byte) (n int, err error) {
    18  	return len(b), nil
    19  }
    20  
    21  func (nc *NilConn) Write(b []byte) (n int, err error) {
    22  	return len(b), nil
    23  }
    24  
    25  func (nc *NilConn) LocalAddr() net.Addr {
    26  	return &net.TCPAddr{
    27  		IP:   net.ParseIP("127.0.0.1"),
    28  		Port: 9090,
    29  	}
    30  }
    31  
    32  func (nc *NilConn) RemoteAddr() net.Addr {
    33  	return &net.TCPAddr{
    34  		IP:   net.ParseIP("127.0.0.1"),
    35  		Port: 9089,
    36  	}
    37  }
    38  
    39  func (nc *NilConn) SetDeadline(t time.Time) error {
    40  	return nil
    41  }
    42  
    43  func (nc *NilConn) SetReadDeadline(t time.Time) error {
    44  	return nil
    45  }
    46  
    47  func (nc *NilConn) SetWriteDeadline(t time.Time) error {
    48  	return nil
    49  }
    50  
    51  func (nc *NilConn) SetSource(s interface{}) {
    52  	return
    53  }
    54  
    55  func (nc *NilConn) Source() interface{} {
    56  	return nil
    57  }