func (c timeoutConn) Write(b []byte) (n int, err error) {
	deadline := time.Now().Add(c.timeout)
	err = c.Conn.SetWriteDeadline(deadline)
	if err != nil {
		return
	}
	return c.Conn.Write(b)
}
Write implements net.Conn.
package privval
import (
	"net"
	"time"
	"github.com/tendermint/tendermint/crypto/ed25519"
)
const (
	defaultTimeoutAcceptSeconds = 3
)
type timeoutError interface {
	Timeout() bool
}
type TCPListenerOption func(*TCPListener)
func TCPListenerTimeoutAccept(timeout time.Duration) TCPListenerOption {
	return func(tl *TCPListener) { tl.timeoutAccept = timeout }
}
func TCPListenerTimeoutReadWrite(timeout time.Duration) TCPListenerOption {
	return func(tl *TCPListener) { tl.timeoutReadWrite = timeout }
}
var _ net.Listener = (*TCPListener)(nil)
type TCPListener struct {
	*net.TCPListener
	secretConnKey ed25519.PrivKey
	timeoutAccept    time.Duration
	timeoutReadWrite time.Duration
}
func NewTCPListener(ln net.Listener, secretConnKey ed25519.PrivKey) *TCPListener {
	return &TCPListener{
		TCPListener:      ln.(*net.TCPListener),
		secretConnKey:    secretConnKey,
		timeoutAccept:    time.Second * defaultTimeoutAcceptSeconds,
		timeoutReadWrite: time.Second * defaultTimeoutReadWriteSeconds,
	}
}
func (ln *TCPListener) Accept() (net.Conn, error) {
	deadline := time.Now().Add(ln.timeoutAccept)
	err := ln.SetDeadline(deadline)
	if err != nil {
		return nil, err
	}
	tc, err := ln.AcceptTCP()
	if err != nil {
		return nil, err
	}
	timeoutConn := newTimeoutConn(tc, ln.timeoutReadWrite)
	secretConn, err := MakeSecretConnection(timeoutConn, ln.secretConnKey)
	if err != nil {
		return nil, err
	}
	return secretConn, nil
}
var _ net.Listener = (*UnixListener)(nil)
type UnixListenerOption func(*UnixListener)
func UnixListenerTimeoutAccept(timeout time.Duration) UnixListenerOption {
	return func(ul *UnixListener) { ul.timeoutAccept = timeout }
}
func UnixListenerTimeoutReadWrite(timeout time.Duration) UnixListenerOption {
	return func(ul *UnixListener) { ul.timeoutReadWrite = timeout }
}
type UnixListener struct {
	*net.UnixListener
	timeoutAccept    time.Duration
	timeoutReadWrite time.Duration
}
func NewUnixListener(ln net.Listener) *UnixListener {
	return &UnixListener{
		UnixListener:     ln.(*net.UnixListener),
		timeoutAccept:    time.Second * defaultTimeoutAcceptSeconds,
		timeoutReadWrite: time.Second * defaultTimeoutReadWriteSeconds,
	}
}
func (ln *UnixListener) Accept() (net.Conn, error) {
	deadline := time.Now().Add(ln.timeoutAccept)
	err := ln.SetDeadline(deadline)
	if err != nil {
		return nil, err
	}
	tc, err := ln.AcceptUnix()
	if err != nil {
		return nil, err
	}
	conn := newTimeoutConn(tc, ln.timeoutReadWrite)
	return conn, nil
}
var _ net.Conn = (*timeoutConn)(nil)
type timeoutConn struct {
	net.Conn
	timeout time.Duration
}
func newTimeoutConn(conn net.Conn, timeout time.Duration) *timeoutConn {
	return &timeoutConn{
		conn,
		timeout,
	}
}
func (c timeoutConn) Read(b []byte) (n int, err error) {
	deadline := time.Now().Add(c.timeout)
	err = c.Conn.SetReadDeadline(deadline)
	if err != nil {
		return
	}
	return c.Conn.Read(b)
}