|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
(*
* This file:
* https://anggtwu.net/OCAML/PipeTest1.ml.html
* https://anggtwu.net/OCAML/PipeTest1.ml
* (find-angg "OCAML/PipeTest1.ml")
* Author: Eduardo Ochs <eduardoochs@gmail.com>
*
* (defun e () (interactive) (find-angg "OCAML/PipeTest1.ml"))
* (find-es "ocaml" "pipe")
* (find-es "ocaml" "Async")
*)
open Core.Std
open Async.Std
let run ~uppercase ~port =
let host_and_port =
Tcp.Server.create
~on_handler_error:`Raise
(Tcp.on_port port)
(fun _addr r w ->
Pipe.transfer (Reader.pipe r) (Writer.pipe w)
~f:(if uppercase then String.uppercase else Fn.id))
in
ignore (host_and_port : (Socket.Address.Inet.t, int) Tcp.Server.t Deferred.t);
Deferred.never ()
let () =
Command.async_basic
~summary:"Start an echo server"
Command.Spec.(
empty
+> flag "-uppercase" no_arg
~doc:" Convert to uppercase before echoing back"
+> flag "-port" (optional_with_default 8765 int)
~doc:" Port to listen on (default 8765)"
)
(fun uppercase port () -> run ~uppercase ~port)
|> Command.run
(* let (r,w) = Pipe.create ();; *)
(* val r : '_a Pipe.Reader.t = <abstr> *)
(* val w : '_a Pipe.Writer.t = <abstr> *)
(*
* (eepitch-ocaml)
* (eepitch-kill)
* (eepitch-ocaml)
#use "PipeTest1.ml";;
* (eepitch-utop)
* (eepitch-kill)
* (eepitch-utop)
* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
* (eepitch-vterm)
* (eepitch-kill)
* (eepitch-vterm)
utop
open Core.Std;;
*)
(*
* Local Variables:
* coding: utf-8-unix
* End:
*)