Documentation ¶
Index ¶
- Constants
- Variables
- type Opts
- type Session
- func (s *Session) Accept() (*Stream, error)
- func (s *Session) Close() error
- func (s *Session) CloseWithErr(err error)
- func (s *Session) Context() context.Context
- func (s *Session) OpenStream() (*Stream, error)
- func (s *Session) Ping(ctx context.Context) error
- func (s *Session) ReserveStreamN(n int32) (reserved int32)
- func (s *Session) Status() SessionStatus
- func (s *Session) SubConn() io.ReadWriteCloser
- type SessionStatus
- type Stream
- func (s *Stream) Close() error
- func (s *Stream) CloseWithErr(err error)
- func (s *Stream) Context() context.Context
- func (s *Stream) ID() int32
- func (s *Stream) Read(p []byte) (n int, err error)
- func (s *Stream) Session() *Session
- func (s *Stream) SetRxWindowSize(n int32) error
- func (s *Stream) Write(p []byte) (n int, err error)
- func (s *Stream) WriteTo(w io.Writer) (int64, error)
Constants ¶
const ( MaxStreamNum = 1<<31 - 1 InitialStreamQuota = 100 )
Variables ¶
var ( ErrSessionClosed = errors.New("session closed") ErrSessionEoL = errors.New("session end of life") ErrStreamQuotaLimit = errors.New("stream quota limit") ErrTooManyStreams = errors.New("too many streams") ErrPayloadOverflowed = errors.New("payload size is to large") ErrKeepaliveTimedOut = errors.New("keepalive ping timed out") ErrIdleTimedOut = errors.New("idle timed out") ErrAcceptNotAllowed = errors.New("accept is not allowed") )
var (
ErrClosedStream = errors.New("closed stream")
)
Functions ¶
This section is empty.
Types ¶
type Opts ¶
type Opts struct { // AllowAccept indicates this Session can accept streams // from peer. If AllowAccept is false and peer sends a SYN // frame, local will send a FIN frame. // On serve this typically should be true and false on client. AllowAccept bool // StreamReceiveWindow sets the default size of receive window when // a stream was opened/accepted. // Minimum rx window size is 64k and maximum is (1<<32 - 1). // If StreamReceiveWindow is invalid, the closest limit will // be used. Which means a zero value is 64k. StreamReceiveWindow int32 // Write buffer size. Default is about 64k. WriteBufferSize int // Read buffer size. Default is 64k. ReadBufferSize int // KeepaliveInterval indicates how long will this Session sends a // ping request to the peer if no data was received. Zero value means no ping will be sent. KeepaliveInterval time.Duration // KeepaliveTimeout indicates how long will this Session be closed with // ErrPingTimeout if no further data (any data, not just a pong) was // received after a keepalive ping was sent. // Default is 10s. KeepaliveTimeout time.Duration // IdleTimeout indicates how long will this Session be closed with // ErrIdleTimeout if no stream is alive. // Zero value means no idle timeout. IdleTimeout time.Duration // WriteTimeout is the timeout for write op. If a write op started and after // WriteTimeout no data was been written, the connection will be closed. // This requires the connection implementing [SetWriteDeadline(t time.Time) error] method. // See [net.Conn] for more details. WriteTimeout time.Duration // The number of concurrent streams that peer can open at a time. // Minimum is initialStreamQuota. MaxConcurrentStreams int32 // OnClose will be called once when the session is closed. OnClose func(session *Session, err error) // contains filtered or unexported fields }
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
func NewSession ¶
func NewSession(c io.ReadWriteCloser, opts Opts) *Session
func (*Session) Accept ¶
Accept accepts a Stream from peer. Session must be created with Opts.AllowAccept. Otherwise, Accept returns ErrAcceptNotAllowed. A Stream must be Accept-ed ASAP. Otherwise, all read operations of this Session (all its streams) will be blocked.
func (*Session) CloseWithErr ¶ added in v0.2.0
func (*Session) Context ¶ added in v0.2.0
Returned context.Context will be canceled with the cause error when Session is dead.
func (*Session) OpenStream ¶
OpenStream opens a stream. Returns: ErrClosedSession if Session was closed. ErrStreamIdOverFlowed if Session has opened too many streams (see MaxStreamNum). Any error that inner connection returns while sending syn frame.
func (*Session) ReserveStreamN ¶ added in v0.2.0
ReserveStreamN tries to reserve N streams for future use. If session reaches the stream id limit, the returned [reserved] will be smaller than n.
func (*Session) Status ¶ added in v0.2.0
func (s *Session) Status() SessionStatus
func (*Session) SubConn ¶
func (s *Session) SubConn() io.ReadWriteCloser
SubConn returns the io.ReadWriteCloser that created this Session. This is for accessing info only. DO NOT r/w/c this sub connection.
type SessionStatus ¶ added in v0.2.0
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
func (*Stream) CloseWithErr ¶ added in v0.2.0
func (*Stream) Context ¶ added in v0.2.0
If stream was closed, the context.Context will be canceled with the cause error.
func (*Stream) SetRxWindowSize ¶
SetRxWindowSize sets the stream rx windows size. If n is invalid, the default/minimum limit will be used. It returns an error if it cannot send a window update frame.