Module Lwt_bytes

Contents

Instructions: Use this module in your project

In the IDE (CLion, Visual Studio Code, Xcode, etc.) you use for your DkSDK project:

  1. Add the following to your project's dependencies/CMakeLists.txt:

    Copy
    DkSDKProject_DeclareAvailable(lwt
        CONSTRAINT "= 5.6.1"
        FINDLIBS lwt lwt.unix)
    DkSDKProject_MakeAvailable(lwt)
  2. Add the Findlib::lwt library to any desired targets in src/*/CMakeLists.txt:

    Copy
    target_link_libraries(YourPackage_YourLibraryName
         # ... existing libraries, if any ...
         Findlib::lwt)
  3. Click your IDE's Build button

Not using DkSDK?

FIRST, do one or all of the following:

  1. Run:

    Copy
    opam install lwt.5.6.1
  2. Edit your dune-project and add:

    Copy
    (package
      (name YourExistingPackage)
      (depends
      ; ... existing dependenices ...
      (lwt (>= 5.6.1))))

    Then run:

    Copy
    dune build *.opam # if this fails, run: dune build
  3. Edit your <package>.opam file and add:

    Copy
    depends: [
      # ... existing dependencies ...
      "lwt" {>= "5.6.1"}
    ]

    Then run:

    Copy
    opam install . --deps-only

FINALLY, add the lwt.unix library to any desired (library)and/or (executable) targets in your **/dune files:

Copy
(library
  (name YourLibrary)
  ; ... existing library options ...
  (libraries
    ; ... existing libraries ...
    lwt.unix))

(executable
  (name YourExecutable)
  ; ... existing executable options ...
  (libraries
    ; ... existing libraries ...
    lwt.unix))
valcreate : ``int-> t

Creates a new byte array of the given size.

vallength :t -> int

Returns the length of the given byte array.

Access

valget :t ->``int-> char

get buffer offset returns the byte at offset offset in buffer.

valset :t ->``int->``char-> unit

get buffer offset value changes the value of the byte at offset offset in buffer to value.

valunsafe_get :t ->``int-> char

Same as get but without bounds checking.

valunsafe_set :t ->``int->``char-> unit

Same as set but without bounds checking.

Conversions

valof_bytes : ``bytes-> t

of_bytes buf returns a newly allocated byte array with the same contents as buf.

valof_string : ``string-> t

of_string buf returns a newly allocated byte array with the same contents as buf.

valto_bytes :t -> bytes

to_bytes buf returns newly allocated bytes with the same contents as buf.

valto_string :t -> string

to_string buf returns a newly allocated string with the same contents as buf.

Copying

valblit :t ->``int-> t ->``int->``int-> unit

blit buf1 ofs1 buf2 ofs2 len copies len bytes from buf1 starting at offset ofs1 to buf2 starting at offset ofs2.

valblit_from_string : ``string->``int-> t ->``int->``int-> unit

Same as blit but the first buffer is a String.t instead of a byte array.

valblit_from_bytes : ``bytes->``int-> t ->``int->``int-> unit

Same as blit but the first buffer is a Bytes.t instead of a byte array.

valblit_to_bytes :t ->``int->``bytes->``int->``int-> unit

Same as blit but the second buffer is a Bytes.t instead of a byte array.

valunsafe_blit :t ->``int-> t ->``int->``int-> unit

Same as blit but without bound checking.

valunsafe_blit_from_bytes : ``bytes->``int-> t ->``int->``int-> unit

Same as Lwt_bytes.blit_from_bytes but without bounds checking.

valunsafe_blit_from_string : ``string->``int-> t ->``int->``int-> unit

Same as Lwt_bytes.blit_from_string but without bounds checking.

valunsafe_blit_to_bytes :t ->``int->``bytes->``int->``int-> unit

Same as Lwt_bytes.blit_to_bytes but without bounds checking.

valproxy :t ->``int->``int-> t

proxy buffer offset length creates a ``proxy''. The returned byte array share the data of buffer but with different bounds.

valextract :t ->``int->``int-> t

extract buffer offset length creates a new byte array of length length and copy the length bytes of buffer at offset into it.

valcopy :t -> t

copy buffer creates a copy of the given byte array.

Filling

valfill :t ->``int->``int->``char-> unit

fill buffer offset length value puts value in all length bytes of buffer starting at offset offset.

valunsafe_fill :t ->``int->``int->``char-> unit

Same as fill but without bounds checking.

IOs

The following functions behave similarly to the ones in Lwt_unix, except they use byte arrays instead of Bytes.t, and they never perform extra copies of the data.

valread :Lwt_unix.file_descr -> t ->``int->``int->``intLwt.t
valwrite :Lwt_unix.file_descr -> t ->``int->``int->``intLwt.t
valrecv :Lwt_unix.file_descr -> t ->``int->``int-> Unix.msg_flaglist``->``intLwt.t

Not implemented on Windows.

valsend :Lwt_unix.file_descr -> t ->``int->``int-> Unix.msg_flaglist``->``intLwt.t

Not implemented on Windows.

valrecvfrom :Lwt_unix.file_descr -> t ->``int->``int-> Unix.msg_flaglist``->``(int *Unix.sockaddr)`` Lwt.t

Not implemented on Windows.

valsendto :Lwt_unix.file_descr -> t ->``int->``int-> Unix.msg_flaglist``-> Unix.sockaddr ->``intLwt.t

Not implemented on Windows.

type io_vector`` = ``{
iov_buffer : t;
iov_offset : int;
iov_length : int;}
val io_vector : ``buffer:t ->``offset:int->``length:int-> io_vector
val recv_msg : ``socket:Lwt_unix.file_descr -> ``io_vectors:io_vectorlist``->``(int *Unix.file_descrlist``)``Lwt.t

Not implemented on Windows.

val send_msg : ``socket:Lwt_unix.file_descr -> ``io_vectors:io_vectorlist``-> ``fds:Unix.file_descrlist``->``intLwt.t

Not implemented on Windows.

Memory mapped files

val map_file : ``fd:Unix.file_descr ->``?pos:int64->``shared:bool->``?size:int->``unit-> t

map_file ~fd ?pos ~shared ?size () maps the file descriptor fd to an array of bytes.

valmapped :t -> bool

mapped buffer returns true iff buffer is a memory mapped file.

typeadvice`` =
| MADV_NORMAL
| MADV_RANDOM
| MADV_SEQUENTIAL
| MADV_WILLNEED
| MADV_DONTNEED
| MADV_MERGEABLE
| MADV_UNMERGEABLE
| MADV_HUGEPAGE
| MADV_NOHUGEPAGE

Type of advise that can be sent to the kernel by the program. See the manual madvise(2) for a description of each.

valmadvise :t ->``int->``int-> advice -> unit

madvise buffer pos len advice advises the kernel how the program will use the memory mapped file between pos and pos + len.

This call is not available on windows.

val page_size : int

Size of pages.

valmincore :t ->``int->``bool array``-> unit

mincore buffer offset states tests whether the given pages are in the system memory (the RAM). The offset argument must be a multiple of page_size. states is used to store the result; each cases is true if the corresponding page is in RAM and false otherwise.

This call is not available on windows and cygwin.

valwait_mincore :t ->``int->``unitLwt.t

wait_mincore buffer offset waits until the page containing the byte at offset offset is in RAM.

This functions is not available on windows and cygwin.