rename Irc_msg to Irc.Msg

This commit is contained in:
tali 2024-01-07 16:29:12 -05:00
parent 150d25b1e0
commit 3d4f9a987e
6 changed files with 12 additions and 13 deletions

View File

@ -1,5 +1,5 @@
(library (library
(package talircd) (package talircd)
(name irc_msg) (name irc)
(inline_tests) (inline_tests)
(preprocess (pps ppx_expect ppx_deriving.show))) (preprocess (pps ppx_expect ppx_deriving.show)))

View File

@ -5,8 +5,8 @@ type t = {
userbase : Userbase.t; userbase : Userbase.t;
user : Userbase.user; user : Userbase.user;
mutable regis : string option * (string * string) option; mutable regis : string option * (string * string) option;
outbox : Irc_msg.t Lwt_stream.t; outbox : Irc.Msg.t Lwt_stream.t;
push_outbox : (Irc_msg.t option -> unit); push_outbox : (Irc.Msg.t option -> unit);
quit : unit Lwt_condition.t; quit : unit Lwt_condition.t;
} }
@ -64,7 +64,7 @@ let on_quit_msg t why =
(* message transmission *) (* message transmission *)
module Rpl = struct module Rpl = struct
open Irc_msg open Irc.Msg
let unknowncommand cmd = make "421" [cmd; "Unknown command"] let unknowncommand cmd = make "421" [cmd; "Unknown command"]
let needmoreparams cmd = make "461" [cmd; "Not enough parameters"] let needmoreparams cmd = make "461" [cmd; "Not enough parameters"]
let tryagain cmd = make "263" [cmd; "Please wait a while and try again."] let tryagain cmd = make "263" [cmd; "Please wait a while and try again."]
@ -72,8 +72,8 @@ module Rpl = struct
let nicknameinuse nick = make "433" [nick; "Nickname is already in use"] let nicknameinuse nick = make "433" [nick; "Nickname is already in use"]
end end
let on_msg t (msg : Irc_msg.t) : unit = let on_msg t (msg : Irc.Msg.t) : unit =
Logs.debug (fun m -> m "%a: %a" pp_sockaddr t.addr Irc_msg.pp msg); Logs.debug (fun m -> m "%a: %a" pp_sockaddr t.addr Irc.Msg.pp msg);
let result = let result =
match msg.command, msg.params with match msg.command, msg.params with
| "NICK", new_nick :: _ -> | "NICK", new_nick :: _ ->

View File

@ -4,5 +4,4 @@
; (inline_tests) ; (inline_tests)
; (preprocess (pps ppx_expect ppx_deriving.show)) ; (preprocess (pps ppx_expect ppx_deriving.show))
(libraries (libraries
lwt lwt.unix logs fmt lwt lwt.unix logs fmt irc))
irc_msg))

View File

@ -14,10 +14,10 @@ let listener ~(port : int) ~(backlog : int) : (fd * sockaddr) Lwt_stream.t =
let accept () = sock >>= Lwt_unix.accept >|= Option.some in let accept () = sock >>= Lwt_unix.accept >|= Option.some in
Lwt_stream.from accept Lwt_stream.from accept
let reader (fd : fd) : Irc_msg.t Lwt_stream.t = let reader (fd : fd) : Irc.Msg.t Lwt_stream.t =
let chunk = Buffer.create 512 in let chunk = Buffer.create 512 in
let rdbuf = Bytes.create 512 in let rdbuf = Bytes.create 512 in
let gets () : Irc_msg.t list option Lwt.t = let gets () : Irc.Msg.t list option Lwt.t =
Lwt.catch Lwt.catch
(fun () -> (fun () ->
Lwt_unix.read fd rdbuf 0 (Bytes.length rdbuf) >>= function Lwt_unix.read fd rdbuf 0 (Bytes.length rdbuf) >>= function
@ -25,7 +25,7 @@ let reader (fd : fd) : Irc_msg.t Lwt_stream.t =
| n -> | n ->
Buffer.add_subbytes chunk rdbuf 0 n; Buffer.add_subbytes chunk rdbuf 0 n;
(* if Buffer.length chunk > 200_000 then panic *) (* if Buffer.length chunk > 200_000 then panic *)
let msgs, rest = Irc_msg.parse (Buffer.contents chunk) in let msgs, rest = Irc.Msg.parse (Buffer.contents chunk) in
Buffer.clear chunk; Buffer.clear chunk;
Buffer.add_string chunk rest; Buffer.add_string chunk rest;
Lwt.return_some msgs) Lwt.return_some msgs)
@ -35,7 +35,7 @@ let reader (fd : fd) : Irc_msg.t Lwt_stream.t =
in in
Lwt_stream.from gets |> Lwt_stream.map_list Fun.id Lwt_stream.from gets |> Lwt_stream.map_list Fun.id
let writer (fd : fd) (obox : Irc_msg.t Lwt_stream.t) : unit Lwt.t = let writer (fd : fd) (obox : Irc.Msg.t Lwt_stream.t) : unit Lwt.t =
let rec writeall bs i = let rec writeall bs i =
if i >= Bytes.length bs then if i >= Bytes.length bs then
Lwt.return_unit Lwt.return_unit
@ -46,7 +46,7 @@ let writer (fd : fd) (obox : Irc_msg.t Lwt_stream.t) : unit Lwt.t =
let buf = Buffer.create 512 in let buf = Buffer.create 512 in
let on_msg msg = let on_msg msg =
Buffer.clear buf; Buffer.clear buf;
Irc_msg.write buf msg; Irc.Msg.write buf msg;
writeall (Buffer.to_bytes buf) 0 writeall (Buffer.to_bytes buf) 0
in in
Lwt.catch Lwt.catch