-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterfaces.go
More file actions
57 lines (48 loc) · 1.63 KB
/
Copy pathinterfaces.go
File metadata and controls
57 lines (48 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package websockets
import (
"context"
"io"
"time"
)
// FrameReaderWriter exposes the raw RFC 6455 framing primitives.
// These always bypass the compression layer (control frames, raw fragments).
type FrameReaderWriter interface {
ReadHeader() (Header, error)
ReadFrame(p []byte) (Frame, error)
WriteFrame(isFinal bool, rsv byte, op OpCode, payload []byte) error
}
// DeadlineManager exposes the low-level network timeout controls.
type DeadlineManager interface {
SetReadDeadline(t time.Time) error
SetWriteDeadline(t time.Time) error
}
// HandlerConfigurator exposes the configuration API for intercepting control frames.
type HandlerConfigurator interface {
SetPingHandler(h PingHandler)
SetPongHandler(h PongHandler)
SetCloseHandler(h CloseHandler)
}
// MessageReaderWriter exposes the high-level, allocation-efficient message layer.
// This is what PerMessageDeflateConn explicitly overrides.
type MessageReaderWriter interface {
ReadMessage(buf []byte) ([]byte, OpCode, error)
WriteMessage(op OpCode, payload []byte) error
StreamMessage(op OpCode, chunkSize int, r io.Reader) error
}
type LifecycleManager interface {
KeepAlive(ctx context.Context, interval time.Duration) error
}
// Connection represents a fully featured, protocol-compliant WebSocket connection.
// It unifies raw framing, pooled message processing, heartbeats, and lifecycles.
type Connection interface {
io.Closer
HandlerConfigurator
DeadlineManager
FrameReaderWriter
MessageReaderWriter
LifecycleManager
// Context returns the connection's lifecycle context, canceled
// when the socket is closed or severed.
Context() context.Context
Subprotocol() string
}