...

Source file src/go.etcd.io/etcd/client/pkg/v3/transport/sockopt.go

Documentation: go.etcd.io/etcd/client/pkg/v3/transport

     1  package transport
     2  
     3  import (
     4  	"syscall"
     5  )
     6  
     7  type Controls []func(network, addr string, conn syscall.RawConn) error
     8  
     9  func (ctls Controls) Control(network, addr string, conn syscall.RawConn) error {
    10  	for _, s := range ctls {
    11  		if err := s(network, addr, conn); err != nil {
    12  			return err
    13  		}
    14  	}
    15  	return nil
    16  }
    17  
    18  type SocketOpts struct {
    19  	// ReusePort enables socket option SO_REUSEPORT [1] which allows rebind of
    20  	// a port already in use. User should keep in mind that flock can fail
    21  	// in which case lock on data file could result in unexpected
    22  	// condition. User should take caution to protect against lock race.
    23  	// [1] https://man7.org/linux/man-pages/man7/socket.7.html
    24  	ReusePort bool `json:"reuse-port"`
    25  	// ReuseAddress enables a socket option SO_REUSEADDR which allows
    26  	// binding to an address in `TIME_WAIT` state. Useful to improve MTTR
    27  	// in cases where etcd slow to restart due to excessive `TIME_WAIT`.
    28  	// [1] https://man7.org/linux/man-pages/man7/socket.7.html
    29  	ReuseAddress bool `json:"reuse-address"`
    30  }
    31  
    32  func getControls(sopts *SocketOpts) Controls {
    33  	ctls := Controls{}
    34  	if sopts.ReuseAddress {
    35  		ctls = append(ctls, setReuseAddress)
    36  	}
    37  	if sopts.ReusePort {
    38  		ctls = append(ctls, setReusePort)
    39  	}
    40  	return ctls
    41  }
    42  
    43  func (sopts *SocketOpts) Empty() bool {
    44  	return !sopts.ReuseAddress && !sopts.ReusePort
    45  }
    46  

View as plain text