CCSDS File Delivery Protocol (CCSDS 727.0-B-5) for space file transfer
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

ocaml-cfdp: enable MDX on lib/eio/*.mli, fix README example types

The cfdp_eio README and lib/eio/*.mli code blocks did not type-check
because env#net needs an explicit subtyping coercion before passing
into connect, and the Eio_main.run wrapper made the example a top-level
side-effect rather than a callable. Refactor into named functions and
project env#net to ': [`Generic] Eio.Net.ty Eio.Resource.t' inline.

Also re-export Filestore_eio from the public Cfdp_eio module and add
the MDX stanza so the .mli examples now run alongside the README.

+41 -27
+6 -6
README.md
··· 40 40 ### Send a file 41 41 42 42 ```ocaml 43 - let () = 44 - Eio_main.run @@ fun env -> 43 + let send_firmware env = 45 44 Eio.Switch.run @@ fun sw -> 46 45 let conn = 47 - Cfdp_eio.connect ~sw ~net:env#net ~host:"flatsat-1" ~port:1734 () 46 + let net = (env#net :> [ `Generic ] Eio.Net.ty Eio.Resource.t) in 47 + Cfdp_eio.connect ~sw ~net ~host:"flatsat-1" ~port:1734 () 48 48 in 49 49 match 50 50 Cfdp_eio.Sender.send_file conn ··· 59 59 ### Receive a file 60 60 61 61 ```ocaml 62 - let () = 63 - Eio_main.run @@ fun env -> 62 + let receive_firmware env = 64 63 Eio.Switch.run @@ fun sw -> 65 64 let conn = 66 - Cfdp_eio.connect ~sw ~net:env#net ~host:"flatsat-1" ~port:1734 () 65 + let net = (env#net :> [ `Generic ] Eio.Net.ty Eio.Resource.t) in 66 + Cfdp_eio.connect ~sw ~net ~host:"flatsat-1" ~port:1734 () 67 67 in 68 68 match 69 69 Cfdp_eio.Receiver.recv_file conn ~dest_dir:(Fpath.v "./incoming") ()
+1 -1
dune
··· 4 4 5 5 (mdx 6 6 (files README.md) 7 - (libraries cfdp cfdp-eio eio_main eio eio.unix fmt fpath)) 7 + (libraries cfdp cfdp-eio eio_main eio eio.core eio.unix fmt fpath))
+2
lib/eio/cfdp_eio.ml
··· 266 266 in 267 267 loop () 268 268 end 269 + 270 + module Filestore_eio = Filestore_eio
+18 -15
lib/eio/cfdp_eio.mli
··· 15 15 {2 Quick Start} 16 16 17 17 {[ 18 - Eio_main.run @@ fun env -> 19 - Eio.Switch.run @@ fun sw -> 20 - let conn = 21 - Cfdp_eio.connect ~sw ~net:env#net ~host:"flatsat-1" ~port:1734 () 22 - in 23 - let result = 24 - Cfdp_eio.Sender.send_file conn ~src:(Fpath.v "firmware.elf") 25 - ~dst:"firmware.elf" 26 - ~on_progress:(fun p -> 27 - Printf.printf "\r%Ld/%Ld" p.bytes_sent p.bytes_total) 28 - () 29 - in 30 - match result with 31 - | Ok tid -> Printf.printf "\nDone: %a\n" Cfdp.pp_transaction_id tid 32 - | Error msg -> Printf.eprintf "Error: %s\n" msg 18 + let run ~env ~sw = 19 + let conn = 20 + Cfdp_eio.connect ~sw ~net:(Eio.Stdenv.net env) ~host:"flatsat-1" 21 + ~port:1734 () 22 + in 23 + let result = 24 + Cfdp_eio.Sender.send_file conn ~src:(Fpath.v "firmware.elf") 25 + ~dst:"firmware.elf" 26 + ~on_progress:(fun p -> 27 + Printf.printf "\r%Ld/%Ld" p.bytes_sent p.bytes_total) 28 + () 29 + in 30 + match result with 31 + | Ok tid -> Fmt.pr "@.Done: %a@." Cfdp.pp_transaction_id tid 32 + | Error msg -> Fmt.epr "Error: %s@." msg 33 33 ]} 34 34 35 35 {2 Wire Format} ··· 119 119 120 120 val recv_pdu : t -> (Cfdp.pdu, string) result 121 121 (** Receive and decode a single PDU. *) 122 + 123 + module Filestore_eio = Filestore_eio 124 + (** Eio filesystem-backed Filestore for CFDP. *)
+4
lib/eio/dune
··· 2 2 (name cfdp_eio) 3 3 (public_name cfdp-eio) 4 4 (libraries cfdp eio fpath fmt logs)) 5 + 6 + (mdx 7 + (files cfdp_eio.mli filestore_eio.mli) 8 + (libraries cfdp-eio cfdp eio eio.unix eio_main fpath fmt))
+10 -5
lib/eio/filestore_eio.mli
··· 6 6 {2 Usage} 7 7 8 8 {[ 9 - Eio_main.run @@ fun env -> 10 - let fs = Filestore_eio.of_path Eio.Path.(Eio.Stdenv.cwd env / "data") in 11 - let () = Filestore_eio.create fs "test.txt" |> Result.get_ok in 9 + let run ~env = 10 + let fs = 11 + Cfdp_eio.Filestore_eio.of_path Eio.Path.(Eio.Stdenv.cwd env / "data") 12 + in 13 + let () = Cfdp_eio.Filestore_eio.v fs "test.txt" |> Result.get_ok in 12 14 let () = 13 - Filestore_eio.write_at fs "test.txt" ~offset:0L 15 + Cfdp_eio.Filestore_eio.write_at fs "test.txt" ~offset:0L 14 16 (Bytes.of_string "hello") 15 17 |> Result.get_ok 16 18 in 17 - ... 19 + let size = 20 + Cfdp_eio.Filestore_eio.file_size fs "test.txt" |> Result.get_ok 21 + in 22 + assert (size = 5L) 18 23 ]} *) 19 24 20 25 (** {1 Errors} *)