conn

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package conn provides shared HTTP/1.1 and HTTP/2 connection handling.

Index

Constants

This section is empty.

Variables

View Source
var ErrHijacked = errors.New("celeris: connection hijacked")

ErrHijacked is returned by ProcessH1 when the connection was hijacked. The engine must not close or reuse the FD after receiving this error.

Functions

func CloseH1 added in v1.1.0

func CloseH1(state *H1State)

CloseH1 releases the cached stream and context (if any) back to their pools.

func CloseH2

func CloseH2(state *H2State)

CloseH2 cleans up H2 state. Releases all streams still held by the manager to prevent memory leaks on connection close.

func ProcessH1

func ProcessH1(ctx context.Context, data []byte, state *H1State, handler stream.Handler,
	write func([]byte)) error

ProcessH1 processes incoming H1 data, parsing requests and calling the handler. The write callback is used to send response bytes back to the connection.

func ProcessH2

func ProcessH2(ctx context.Context, data []byte, state *H2State, _ stream.Handler,
	write func([]byte), _ H2Config) error

ProcessH2 processes incoming H2 data. On first call, validates the client preface and sends server settings. PING, SETTINGS ACK) and falls back to x/net framer for complex types.

Types

type H1State

type H1State struct {
	RemoteAddr         string
	HijackFn           func() (net.Conn, error)                            // set by engine; nil if unsupported
	MaxRequestBodySize int64                                               // 0 = use default (100 MB)
	OnExpectContinue   func(method, path string, headers [][2]string) bool // nil = always accept
	OnDetach           func()                                              // set by engine; called on Context.Detach
	Detached           bool                                                // set by OnDetach; breaks pipelining loop
	// contains filtered or unexported fields
}

H1State holds per-connection H1 parsing state.

func NewH1State

func NewH1State() *H1State

NewH1State creates a new H1 connection state with zero-copy header parsing.

func (*H1State) UpdateWriteFn added in v1.2.0

func (s *H1State) UpdateWriteFn(fn func([]byte))

UpdateWriteFn replaces the response adapter's write function. Called by OnDetach to route StreamWriter writes through the mutex-guarded writeFn.

type H2Config

type H2Config struct {
	MaxConcurrentStreams uint32
	InitialWindowSize    uint32
	MaxFrameSize         uint32
	MaxRequestBodySize   int64 // 0 = use default (100 MB)
}

H2Config holds H2 connection configuration.

type H2State

type H2State struct {
	// contains filtered or unexported fields
}

H2State holds per-connection H2 state.

func NewH2State

func NewH2State(handler stream.Handler, cfg H2Config, write func([]byte), wakeupFD int) *H2State

NewH2State creates a new H2 connection state. wakeupFD is an eventfd used to signal the event loop when handler goroutines enqueue responses (-1 to disable, falling back to polling).

func (*H2State) DrainWriteQueue added in v1.1.0

func (s *H2State) DrainWriteQueue(write func([]byte))

DrainWriteQueue drains async handler responses to the write function. Called from the event loop thread (outside H2State.mu).

func (*H2State) SetRemoteAddr added in v1.1.0

func (s *H2State) SetRemoteAddr(addr string)

SetRemoteAddr sets the remote address on the H2 stream manager so that all streams created on this connection inherit the peer address.

func (*H2State) WriteQueuePending added in v1.1.0

func (s *H2State) WriteQueuePending() bool

WriteQueuePending returns true if the write queue has pending data.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL