package atacama
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=143ee67ef8eb4e4a7ef27ca96c4644cc7e8d7935cfb86c76a737c7badaa2060e
sha512=7de1100df32120f3a9541183569fb3d48525e70c981dbac1aa1760d3b78a39c41eb3f0bbe5be7e7ff639dfbf421b5f7c3f0e467199dc7d263a16a0ca7549eec8
README.md.html
README.md
Atacama
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 an Atacama server, we can also specify a transport module.
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 an Atacama server.