package bytesrw
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
Composable byte stream readers and writers for OCaml
Install
dune-project
Dependency
Authors
Maintainers
Sources
bytesrw-0.3.0.tbz
sha512=388858b0db210a62a16f56655746fdfadbc64b22c2abb5ed5a12b2872e4f8c34f045cdb953a5dda9b92f0003c7f9f34d70fa5b5bb19fd32fb6121bbaeb7ceba0
doc/src/bytesrw.unix/bytesrw_unix.ml.html
Source file bytesrw_unix.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61(*--------------------------------------------------------------------------- Copyright (c) 2024 The bytesrw programmers. All rights reserved. SPDX-License-Identifier: ISC ---------------------------------------------------------------------------*) open Bytesrw (* Readers and writers. *) let rec current_pos fd = match Unix.lseek fd 0 Unix.SEEK_CUR with | exception Unix.Unix_error (ESPIPE, _, _) (* sockets *) -> 0 | exception Unix.Unix_error (EINTR, _, _) -> current_pos fd | pos -> if pos < 0 then 0 else pos let bytes_reader_of_fd ?pos ?(slice_length = Bytes.Slice.unix_io_buffer_size) fd = let pos = match pos with Some pos -> pos | None -> current_pos fd in let b = Bytes.create (Bytes.Slice.check_length slice_length) in let rec read () = match Unix.read fd b 0 slice_length with | 0 -> Bytes.Slice.eod | count -> Bytes.Slice.make b ~first:0 ~length:count | exception Unix.Unix_error (Unix.EINTR, _, _) -> read () in Bytes.Reader.make ~pos ~slice_length read let bytes_writer_of_fd ?pos ?(slice_length = Bytes.Slice.unix_io_buffer_size) fd = let pos = match pos with Some pos -> pos | None -> current_pos fd in let rec write = function | s when Bytes.Slice.is_eod s -> () | s -> let b = Bytes.Slice.bytes s in let first = Bytes.Slice.first s and length = Bytes.Slice.length s in match Unix.single_write fd b first length with | count when count = length -> () | count -> write (Option.get (Bytes.Slice.drop count s)) | exception Unix.Unix_error (Unix.EINTR, _, _) -> write s in Bytes.Writer.make ~pos ~slice_length write (* Sockets *) let rec shutdown fd dir = try Unix.shutdown fd dir with | Unix.Unix_error (Unix.EINTR, _, _) -> shutdown fd dir let bytes_writer_of_socket_fd ?pos ?(slice_length = Bytes.Slice.unix_io_buffer_size) fd = let rec write = function | s when Bytes.Slice.is_eod s -> shutdown fd SHUTDOWN_SEND; () | s -> let b = Bytes.Slice.bytes s in let first = Bytes.Slice.first s and length = Bytes.Slice.length s in match Unix.single_write fd b first length with | count when count = length -> () | count -> write (Option.get (Bytes.Slice.drop count s)) | exception Unix.Unix_error (Unix.EINTR, _, _) -> write s in Bytes.Writer.make ?pos ~slice_length write
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>