func (p *Transport) ReadFirst(ctx context.Context) (frame core.BufferedFrame, err error) {
	select {
	case <-ctx.Done():
		err = ctx.Err()
	default:
		frame, err = p.conn.Read()
		if err != nil {
			err = errors.Wrap(err, "read first frame failed")
		}
	}
	if err != nil {
		_ = p.Close()
	}
	return
}
ReadFirst reads first frame.
package transport
import (
	"context"
	"fmt"
	"io"
	"runtime"
	"sync"
	"time"
	"github.com/pkg/errors"
	"github.com/rsocket/rsocket-go/core"
	"github.com/rsocket/rsocket-go/core/framing"
	"github.com/rsocket/rsocket-go/internal/buffer"
	"github.com/rsocket/rsocket-go/internal/common"
	"github.com/rsocket/rsocket-go/logger"
)
var (
	errTransportClosed = errors.New("transport closed")
	errNoHandler       = errors.New("you must register a handler")
)
type FrameHandler = func(frame core.BufferedFrame) (err error)
type ServerTransportAcceptor = func(ctx context.Context, tp *Transport, onClose func(*Transport))
type ServerTransport interface {
	io.Closer
	Accept(acceptor ServerTransportAcceptor)
	Listen(ctx context.Context, notifier chan<- bool) error
}
type EventType int
const (
	OnSetup EventType = iota
	OnResume
	OnLease
	OnResumeOK
	OnFireAndForget
	OnMetadataPush
	OnRequestResponse
	OnRequestStream
	OnRequestChannel
	OnPayload
	OnRequestN
	OnError
	OnErrorWithZeroStreamID
	OnCancel
	OnKeepalive
	handlerLen = int(OnKeepalive) + 1
)
type Transport struct {
	mu          sync.RWMutex
	conn        Conn
	maxLifetime time.Duration
	lastRcvPos  uint64
	once        sync.Once
	handlers    [handlerLen]FrameHandler
}
func NewTransport(c Conn) *Transport {
	return &Transport{
		conn:        c,
		maxLifetime: common.DefaultKeepaliveMaxLifetime,
	}
}
func IsNoHandlerError(err error) bool {
	return err == errNoHandler
}
func (p *Transport) Handle(event EventType, handler FrameHandler) {
	p.mu.Lock()
	p.handlers[int(event)] = handler
	p.mu.Unlock()
}
func (p *Transport) Connection() Conn {
	return p.conn
}
func (p *Transport) SetLifetime(lifetime time.Duration) {
	if lifetime < 1 {
		return
	}
	p.maxLifetime = lifetime
}
func (p *Transport) Send(frame core.WriteableFrame, flush bool) (err error) {
	defer func() {
		if err == nil {
			frame.Done()
		}
	}()
	if p == nil || p.conn == nil {
		err = errTransportClosed
		return
	}
	err = p.conn.Write(frame)
	if err != nil {
		return
	}
	if !flush {
		return
	}
	err = p.conn.Flush()
	return
}
func (p *Transport) Flush() (err error) {
	if p == nil || p.conn == nil {
		err = errTransportClosed
		return
	}
	err = p.conn.Flush()
	return
}
func (p *Transport) Close() (err error) {
	p.once.Do(func() {
		err = p.conn.Close()
	})
	return
}