aboutsummaryrefslogtreecommitdiffstats
path: root/lib/transport.ml
diff options
context:
space:
mode:
authorMarcos Magueta <maguetamarcos@gmail.com>2026-04-20 21:55:07 -0300
committerGitHub <noreply@github.com>2026-04-20 21:55:07 -0300
commitfdc63e730f91a4605ed4ff96a908e1f5e822d1bb (patch)
tree36b0a66b81fc201a426171e190975289640cd579 /lib/transport.ml
parentd3708bb28adcd0220142f1890ab96bfd2df637d3 (diff)
downloadSakura-fdc63e730f91a4605ed4ff96a908e1f5e822d1bb.tar.gz
Sakura-fdc63e730f91a4605ed4ff96a908e1f5e822d1bb.zip
New Server & Manipulation refactor
Co-authored-by: Estevan Castilho <tevo@riajuu.net>
Diffstat (limited to '')
-rw-r--r--lib/transport.ml41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/transport.ml b/lib/transport.ml
new file mode 100644
index 0000000..5130a2d
--- /dev/null
+++ b/lib/transport.ml
@@ -0,0 +1,41 @@
+module type TRANSPORT = sig
+ type t
+ type connection
+ type options
+
+ val create : options -> t
+
+ val listen : t -> unit
+ val accept : t -> connection
+
+ val input : connection -> in_channel
+ val output : connection -> out_channel
+end
+
+(* TODO: move this into TCP once we have a proper configuration system *)
+type tcp_options = {
+ address_family : Unix.socket_domain;
+ address : Unix.sockaddr
+}
+
+module TCP : (TRANSPORT with type options = tcp_options) = struct
+ type t = Unix.file_descr
+ type connection = Unix.file_descr
+ type options = tcp_options
+
+ let create { address_family; address } =
+ let socket = Unix.socket address_family Unix.SOCK_STREAM 0 in
+ Unix.setsockopt socket Unix.SO_REUSEADDR true;
+ Unix.setsockopt socket Unix.SO_REUSEPORT true;
+ Unix.bind socket address;
+ socket
+
+ let listen fd = Unix.listen fd 5
+
+ let accept fd =
+ let (conn, _) = Unix.accept fd in
+ conn
+
+ let input = Unix.in_channel_of_descr
+ let output = Unix.out_channel_of_descr
+end