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
(package talircd)
(name irc_msg)
(name irc)
(inline_tests)
(preprocess (pps ppx_expect ppx_deriving.show)))

View File

@ -5,8 +5,8 @@ type t = {
userbase : Userbase.t;
user : Userbase.user;
mutable regis : string option * (string * string) option;
outbox : Irc_msg.t Lwt_stream.t;
push_outbox : (Irc_msg.t option -> unit);
outbox : Irc.Msg.t Lwt_stream.t;
push_outbox : (Irc.Msg.t option -> unit);
quit : unit Lwt_condition.t;
}
@ -64,7 +64,7 @@ let on_quit_msg t why =
(* message transmission *)
module Rpl = struct
open Irc_msg
open Irc.Msg
let unknowncommand cmd = make "421" [cmd; "Unknown command"]
let needmoreparams cmd = make "461" [cmd; "Not enough parameters"]
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"]
end
let on_msg t (msg : Irc_msg.t) : unit =
Logs.debug (fun m -> m "%a: %a" pp_sockaddr t.addr Irc_msg.pp msg);
let on_msg t (msg : Irc.Msg.t) : unit =
Logs.debug (fun m -> m "%a: %a" pp_sockaddr t.addr Irc.Msg.pp msg);
let result =
match msg.command, msg.params with
| "NICK", new_nick :: _ ->

View File

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

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
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 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
(fun () ->
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 ->
Buffer.add_subbytes chunk rdbuf 0 n;
(* 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.add_string chunk rest;
Lwt.return_some msgs)
@ -35,7 +35,7 @@ let reader (fd : fd) : Irc_msg.t Lwt_stream.t =
in
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 =
if i >= Bytes.length bs then
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 on_msg msg =
Buffer.clear buf;
Irc_msg.write buf msg;
Irc.Msg.write buf msg;
writeall (Buffer.to_bytes buf) 0
in
Lwt.catch