stream

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFiberWebSocketHandler

func NewFiberWebSocketHandler(app *fiber.App, system *vivid.ActorSystem, configurator ...Configurator) fiber.Handler

NewFiberWebSocketHandler 创建一个 fiber.Handler,它将会对请求进行 WebSocket 升级,并采用 Actor 对其进行维护。

  • 这看来似乎是必须的,如果你要对消息进行处理,那么请在 Configurator 内指定 Configuration.WithPerformance 可选项,这可以让你得到 Stream 的 vivid.ActorContext,并对其进行控制。

在 Stream 的 vivid.ActorContext 中会传入三个特殊消息,你可以选择使用它们:

  • stream.Writer:在 Stream Actor 启动后,将会收到一个写入器,这个写入器接收 *stream.Packet 类型的消息,它将会将消息写入到连接中。
  • *websocket.Conn:这是 WebSocket 的特殊消息,你可以获取它来进行额外的操作。
  • *stream.Packet:当收到该消息,也就意味着存在需要处理的数据包。

Types

type Actor

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

func NewStream

func NewStream(conn Stream, configurator ...Configurator) *Actor

func (*Actor) OnReceive

func (c *Actor) OnReceive(ctx vivid.ActorContext)

type Configuration

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

Configuration 流配置

func (*Configuration) WithPerformance

func (c *Configuration) WithPerformance(performance behavior.Performance[vivid.ActorContext])

WithPerformance 设置流的行为表现,你可以像控制 Actor 一样控制它

type Configurator

type Configurator interface {
	Configure(c *Configuration)
}

type FunctionalConfigurator

type FunctionalConfigurator func(c *Configuration)

func (FunctionalConfigurator) Configure

func (f FunctionalConfigurator) Configure(c *Configuration)

type GNETEventHandler

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

func NewGNETEventHandler

func NewGNETEventHandler(system *vivid.ActorSystem, configurator ...Configurator) *GNETEventHandler

func (*GNETEventHandler) OnBoot

func (g *GNETEventHandler) OnBoot(eng gnet.Engine) (action gnet.Action)

func (*GNETEventHandler) OnClose

func (g *GNETEventHandler) OnClose(c gnet.Conn, err error) (action gnet.Action)

func (*GNETEventHandler) OnOpen

func (g *GNETEventHandler) OnOpen(c gnet.Conn) (out []byte, action gnet.Action)

func (*GNETEventHandler) OnShutdown

func (g *GNETEventHandler) OnShutdown(eng gnet.Engine)

func (*GNETEventHandler) OnTick

func (g *GNETEventHandler) OnTick() (delay time.Duration, action gnet.Action)

func (*GNETEventHandler) OnTraffic

func (g *GNETEventHandler) OnTraffic(c gnet.Conn) (action gnet.Action)

type Packet

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

func NewPacket

func NewPacket() *Packet

func NewPacketC

func NewPacketC(ctx any) *Packet

func NewPacketD

func NewPacketD(data []byte) *Packet

func NewPacketDC

func NewPacketDC(data []byte, ctx any) *Packet

func NewPacketS

func NewPacketS(data string) *Packet

func NewPacketSC

func NewPacketSC(data string, ctx any) *Packet

func (*Packet) Context

func (p *Packet) Context() any

func (*Packet) Data

func (p *Packet) Data() []byte

func (*Packet) Derivation

func (p *Packet) Derivation(data []byte) *Packet

Derivation 继承数据包上下文派生一个新的数据包

func (*Packet) SetContext

func (p *Packet) SetContext(ctx any) *Packet

func (*Packet) SetData

func (p *Packet) SetData(data []byte) *Packet

func (*Packet) SetString

func (p *Packet) SetString(data string) *Packet

type Stream

type Stream interface {
	Write(packet *Packet) error

	Close() error
}

type Writer

type Writer = vivid.ActorRef

Writer 是一个流式写入器,它是来自 Stream Actor 的写入器引用,接收 Packet 并将其写入到 Stream 中

type WriterCreatedHook

type WriterCreatedHook interface {
	Stream

	OnWriterCreated(writer Writer)
}

Jump to

Keyboard shortcuts

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