package atacama
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=70656f50054a099325ee8f11c6b5e7146f66d92bcaa1f442e75bf4518a518ac0
sha512=3b54002348dcf8433bcd7a8a8d168f4d20b8f991240ea531f0aae83930b6c8b9faf09a2edc83e1b6a176f55b772756f67bfba09a314fb1c0e13675f044e390e6
Description
Atacama is a modern, pure OCaml socket pool for Riot inspired by Thousand Island. It aims to be easy to understand and reason about, while also being at least as stable and performant as the alternatives.
README
Atacama
Atacama is a modern, pure OCaml socket pool for Riot inspired by Thousand Island. It aims to be easy to understand and reason about, while also being at least as stable and performant as the alternatives.
Getting Started
opam install atacama
Usage
To start a Atacama server, you just specify a port to bind to, and a module that will handle the connections.
let (Ok pid) = Atacama.start_link ~port:2112 (module Echo) initial_state in
In this case, our Echo
handler looks like this:
module Echo = struct
open Atacama.Handler
include Atacama.Handler.Default
type state = int
let handle_data data socket state =
Logger.info (fun f -> f "[%d] echo: %s" state (Bigstringaf.to_string data));
let (Ok _bytes) = Atacama.Socket.send socket data in
Continue (state+1)
end
Custom lifecycle functions can be specified, but sensible defaults are available in the Atacama.Handler.Default
module that you can include to get started quickly.
Custom Transports
When starting a Atacama server, we can also specify a transport module.
let (Ok pid) = Atacama.start_link
~port:2112
~transport_module:(module Custom_transport)
(module Echo) in
A transport is a module that implements Atacama.Transport.Intf
, which defines how to listen, connect, and accept sockets, how to handshake new connections, and how to send and receive data.
Clear Tcp sockets are provided and used by default when starting a Atacama server.