Documentation ¶
Index ¶
- Constants
- type Code
- type Config
- type Controller
- type Handler
- type WebsocketConnection
- type WebsocketConnectionImpl
- func (c *WebsocketConnectionImpl) Close() error
- func (c *WebsocketConnectionImpl) ReadJSON(v interface{}) error
- func (c *WebsocketConnectionImpl) SetPongHandler(h func(string) error)
- func (c *WebsocketConnectionImpl) SetReadDeadline(deadline time.Time) error
- func (c *WebsocketConnectionImpl) SetWriteDeadline(deadline time.Time) error
- func (c *WebsocketConnectionImpl) WriteControl(messageType int, deadline time.Time) error
- func (c *WebsocketConnectionImpl) WriteJSON(v interface{}) error
Constants ¶
View Source
const ( // PingPeriod defines the interval at which ping messages are sent to the client. // This value must be less than pongWait, cause it that case the server ensures it sends a ping well before the PongWait // timeout elapses. Each new pong message resets the server's read deadline, keeping the connection alive as long as // the client is responsive. // // Example: // At t=9, the server sends a ping, initial read deadline is t=10 (for the first message) // At t=10, the client responds with a pong. The server resets its read deadline to t=20. // At t=18, the server sends another ping. If the client responds with a pong at t=19, the read deadline is extended to t=29. // // In case of failure: // If the client stops responding, the server will send a ping at t=9 but won't receive a pong by t=10. The server then closes the connection. PingPeriod = (PongWait * 9) / 10 // PongWait specifies the maximum time to wait for a pong response message from the peer // after sending a ping PongWait = 10 * time.Second // WriteWait specifies a timeout for the write operation. If the write // isn't completed within this duration, it fails with a timeout error. // SetWriteDeadline ensures the write operation does not block indefinitely // if the client is slow or unresponsive. This prevents resource exhaustion // and allows the server to gracefully handle timeouts for delayed writes. WriteWait = 10 * time.Second // DefaultInactivityTimeout is the default duration a WebSocket connection can remain open without any active subscriptions // before being automatically closed DefaultInactivityTimeout time.Duration = 1 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { MaxSubscriptionsPerConnection uint64 MaxResponsesPerSecond uint64 // InactivityTimeout specifies the duration a WebSocket connection can remain open without any active subscriptions // before being automatically closed InactivityTimeout time.Duration }
func NewDefaultWebsocketConfig ¶
func NewDefaultWebsocketConfig() Config
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
func NewWebSocketController ¶
func NewWebSocketController( logger zerolog.Logger, config Config, conn WebsocketConnection, dataProviderFactory dp.DataProviderFactory, ) *Controller
func (*Controller) HandleConnection ¶
func (c *Controller) HandleConnection(ctx context.Context)
HandleConnection manages the lifecycle of a WebSocket connection, including setup, message processing, and graceful shutdown.
Parameters: - ctx: The context for controlling cancellation and timeouts.
type Handler ¶
type Handler struct { *common.HttpHandler // contains filtered or unexported fields }
func NewWebSocketHandler ¶
type WebsocketConnection ¶
type WebsocketConnectionImpl ¶
type WebsocketConnectionImpl struct {
// contains filtered or unexported fields
}
func NewWebsocketConnection ¶
func NewWebsocketConnection(conn *websocket.Conn) *WebsocketConnectionImpl
func (*WebsocketConnectionImpl) Close ¶
func (c *WebsocketConnectionImpl) Close() error
func (*WebsocketConnectionImpl) ReadJSON ¶
func (c *WebsocketConnectionImpl) ReadJSON(v interface{}) error
func (*WebsocketConnectionImpl) SetPongHandler ¶
func (c *WebsocketConnectionImpl) SetPongHandler(h func(string) error)
func (*WebsocketConnectionImpl) SetReadDeadline ¶
func (c *WebsocketConnectionImpl) SetReadDeadline(deadline time.Time) error
func (*WebsocketConnectionImpl) SetWriteDeadline ¶
func (c *WebsocketConnectionImpl) SetWriteDeadline(deadline time.Time) error
func (*WebsocketConnectionImpl) WriteControl ¶
func (c *WebsocketConnectionImpl) WriteControl(messageType int, deadline time.Time) error
func (*WebsocketConnectionImpl) WriteJSON ¶
func (c *WebsocketConnectionImpl) WriteJSON(v interface{}) error
Source Files ¶
Click to show internal directories.
Click to hide internal directories.