any-sync/net/transport/transport.go
2023-05-26 19:18:51 +02:00

35 lines
1009 B
Go

package transport
import (
"context"
"net"
"time"
)
// Transport is a common interface for a network transport
type Transport interface {
// SetAccepter sets accepter that will be called for new connections
// this method should be called before app start
SetAccepter(accepter Accepter)
// Dial creates a new connection by given address
Dial(ctx context.Context, addr string) (mc MultiConn, err error)
}
// MultiConn is an object of multiplexing connection containing handshake info
type MultiConn interface {
// Context returns the connection context that contains handshake details
Context() context.Context
// Accept accepts new sub connections
Accept() (conn net.Conn, err error)
// Open opens new sub connection
Open(ctx context.Context) (conn net.Conn, err error)
// LastUsage returns the time of the last connection activity
LastUsage() time.Time
// Close closes the connection and all sub connections
Close() error
}
type Accepter interface {
Accept(mc MultiConn) (err error)
}