github.com/unionj-cloud/go-doudou/v2@v2.3.5/toolkit/memberlist/net_conn_interface.go (about)

     1  package memberlist
     2  
     3  import (
     4  	"net"
     5  	"time"
     6  )
     7  
     8  //go:generate mockgen -destination ./mock/mock_net_conn_interface.go -package mock -source=./net_conn_interface.go
     9  
    10  // Conn is a generic stream-oriented network connection.
    11  //
    12  // Multiple goroutines may invoke methods on a Conn simultaneously.
    13  type Conn interface {
    14  	// Read reads data from the connection.
    15  	// Read can be made to time out and return an error after a fixed
    16  	// time limit; see SetDeadline and SetReadDeadline.
    17  	Read(b []byte) (n int, err error)
    18  
    19  	// Write writes data to the connection.
    20  	// Write can be made to time out and return an error after a fixed
    21  	// time limit; see SetDeadline and SetWriteDeadline.
    22  	Write(b []byte) (n int, err error)
    23  
    24  	// Close closes the connection.
    25  	// Any blocked Read or Write operations will be unblocked and return errors.
    26  	Close() error
    27  
    28  	// LocalAddr returns the local network address.
    29  	LocalAddr() net.Addr
    30  
    31  	// RemoteAddr returns the remote network address.
    32  	RemoteAddr() net.Addr
    33  
    34  	// SetDeadline sets the read and write deadlines associated
    35  	// with the connection. It is equivalent to calling both
    36  	// SetReadDeadline and SetWriteDeadline.
    37  	//
    38  	// A deadline is an absolute time after which I/O operations
    39  	// fail instead of blocking. The deadline applies to all future
    40  	// and pending I/O, not just the immediately following call to
    41  	// Read or Write. After a deadline has been exceeded, the
    42  	// connection can be refreshed by setting a deadline in the future.
    43  	//
    44  	// If the deadline is exceeded a call to Read or Write or to other
    45  	// I/O methods will return an error that wraps os.ErrDeadlineExceeded.
    46  	// This can be tested using errors.Is(err, os.ErrDeadlineExceeded).
    47  	// The error's Timeout method will return true, but note that there
    48  	// are other possible errors for which the Timeout method will
    49  	// return true even if the deadline has not been exceeded.
    50  	//
    51  	// An idle timeout can be implemented by repeatedly extending
    52  	// the deadline after successful Read or Write calls.
    53  	//
    54  	// A zero value for t means I/O operations will not time out.
    55  	SetDeadline(t time.Time) error
    56  
    57  	// SetReadDeadline sets the deadline for future Read calls
    58  	// and any currently-blocked Read call.
    59  	// A zero value for t means Read will not time out.
    60  	SetReadDeadline(t time.Time) error
    61  
    62  	// SetWriteDeadline sets the deadline for future Write calls
    63  	// and any currently-blocked Write call.
    64  	// Even if write times out, it may return n > 0, indicating that
    65  	// some of the data was successfully written.
    66  	// A zero value for t means Write will not time out.
    67  	SetWriteDeadline(t time.Time) error
    68  }