glisten/handler
Types
pub type Handler(data) {
Handler(
socket: Socket,
initial_data: data,
loop: LoopFn(data),
on_init: Option(fn(Subject(HandlerMessage)) -> Nil),
on_close: Option(fn(Subject(HandlerMessage)) -> Nil),
transport: Transport,
)
}
Constructors
-
Handler( socket: Socket, initial_data: data, loop: LoopFn(data), on_init: Option(fn(Subject(HandlerMessage)) -> Nil), on_close: Option(fn(Subject(HandlerMessage)) -> Nil), transport: Transport, )
pub type HandlerFunc(data) =
fn(BitString, LoopState(data)) -> actor.Next(LoopState(data))
All message types that the handler will receive, or that you can send to the handler process
pub type HandlerMessage {
Close
Ready
ReceiveMessage(BitString)
SendMessage(BitBuilder)
Ssl(socket: Port, data: BitString)
SslClosed(Nil)
Tcp(socket: Port, data: BitString)
TcpClosed(Nil)
}
Constructors
-
Close
-
Ready
-
ReceiveMessage(BitString)
-
SendMessage(BitBuilder)
-
Ssl(socket: Port, data: BitString)
-
SslClosed(Nil)
-
Tcp(socket: Port, data: BitString)
-
TcpClosed(Nil)
pub type LoopFn(data) =
fn(HandlerMessage, LoopState(data)) ->
actor.Next(LoopState(data))
Functions
pub fn func(handler func: fn(BitString, LoopState(a)) ->
Next(LoopState(a))) -> fn(HandlerMessage, LoopState(a)) ->
Next(LoopState(a))
This helper will generate a TCP handler that will call your handler function with the BitString data in the packet as well as the LoopState, with any associated state data you are maintaining