type Listener … type Dialer … type Server … // Dial uses the dialer to make a new connection, wraps the returned // reader and writer using the framer to make a stream, and then builds // a connection on top of that stream using the binder. // // The returned Connection will operate independently using the Preempter and/or // Handler provided by the Binder, and will release its own resources when the // connection is broken, but the caller may Close it earlier to stop accepting // (or sending) new requests. func Dial(ctx context.Context, dialer Dialer, binder Binder) (*Connection, error) { … } // NewServer starts a new server listening for incoming connections and returns // it. // This returns a fully running and connected server, it does not block on // the listener. // You can call Wait to block on the server, or Shutdown to get the sever to // terminate gracefully. // To notice incoming connections, use an intercepting Binder. func NewServer(ctx context.Context, listener Listener, binder Binder) *Server { … } // Wait returns only when the server has shut down. func (s *Server) Wait() error { … } // Shutdown informs the server to stop accepting new connections. func (s *Server) Shutdown() { … } // run accepts incoming connections from the listener, // If IdleTimeout is non-zero, run exits after there are no clients for this // duration, otherwise it exits only on error. func (s *Server) run(ctx context.Context) { … } // NewIdleListener wraps a listener with an idle timeout. // // When there are no active connections for at least the timeout duration, // calls to Accept will fail with ErrIdleTimeout. // // A connection is considered inactive as soon as its Close method is called. func NewIdleListener(timeout time.Duration, wrap Listener) Listener { … } type idleListener … // Accept accepts an incoming connection. // // If an incoming connection is accepted concurrent to the listener being closed // due to idleness, the new connection is immediately closed. func (l *idleListener) Accept(ctx context.Context) (io.ReadWriteCloser, error) { … } func (l *idleListener) Close() error { … } func (l *idleListener) Dialer() Dialer { … } func (l *idleListener) timerExpired() { … } func (l *idleListener) connClosed() { … } type idleListenerConn … func (l *idleListener) newConn(rwc io.ReadWriteCloser) *idleListenerConn { … } func (c *idleListenerConn) Read(p []byte) (int, error) { … } func (c *idleListenerConn) Write(p []byte) (int, error) { … } func (c *idleListenerConn) Close() error { … }