Module ThreadUnix

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(ocaml
        CONSTRAINT "= 4.14.0"
        FINDLIBS str unix runtime_events threads dynlink)
    DkSDKProject_MakeAvailable(ocaml)
  2. Add the Findlib::ocaml library to any desired targets in src/*/CMakeLists.txt:

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

Not using DkSDK?

FIRST, do one or all of the following:

  1. Run:

    Copy
    opam install ocaml.4.14.0
  2. Edit your dune-project and add:

    Copy
    (package
      (name YourExistingPackage)
      (depends
      ; ... existing dependenices ...
      (ocaml (>= 4.14.0))))

    Then run:

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

    Copy
    depends: [
      # ... existing dependencies ...
      "ocaml" {>= "4.14.0"}
    ]

    Then run:

    Copy
    opam install . --deps-only

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

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

(executable
  (name YourExecutable)
  ; ... existing executable options ...
  (libraries
    ; ... existing libraries ...
    unix threads))

Process handling

valexecv : ``string->``string array``-> unit
valexecve : ``string->``string array``->``string array``-> unit
valexecvp : ``string->``string array``-> unit
valwait : ``unit->int *Unix.process_status
valwaitpid :Unix.wait_flaglist``->``int->int *Unix.process_status
valsystem : ``string-> Unix.process_status

Basic input/output

valread :Unix.file_descr ->``bytes->``int->``int-> int
valwrite :Unix.file_descr ->``bytes->``int->``int-> int
valwrite_substring :Unix.file_descr ->``string->``int->``int-> int

Input/output with timeout

valtimed_read :Unix.file_descr ->``bytes->``int->``int->``float-> int
valtimed_write :Unix.file_descr ->``bytes->``int->``int->``float-> int

Behave as ThreadUnix.read and ThreadUnix.write, except that Unix_error(ETIMEDOUT,_,_) is raised if no data is available for reading or ready for writing after d seconds. The delay d is given in the fifth argument, in seconds.

valtimed_write_substring :Unix.file_descr ->``string->``int->``int->``float-> int

Polling

valselect :Unix.file_descrlist``-> Unix.file_descrlist``-> Unix.file_descrlist``->``float-> Unix.file_descrlist`` *Unix.file_descrlist`` *Unix.file_descr list

Pipes and redirections

valpipe : ``?cloexec:bool->``unit-> Unix.file_descr*Unix.file_descr
valopen_process_in : ``string-> in_channel
valopen_process_out : ``string-> out_channel
valopen_process : ``string-> in_channel*out_channel

Time

valsleep : ``int-> unit

Sockets

valsocket : ``?cloexec:bool-> Unix.socket_domain -> Unix.socket_type ->``int-> Unix.file_descr
valaccept : ``?cloexec:bool-> Unix.file_descr -> Unix.file_descr*Unix.sockaddr
valconnect :Unix.file_descr -> Unix.sockaddr -> unit
valrecv :Unix.file_descr ->``bytes->``int->``int-> Unix.msg_flaglist``-> int
valrecvfrom :Unix.file_descr ->``bytes->``int->``int-> Unix.msg_flaglist``->int *Unix.sockaddr
valsend :Unix.file_descr ->``bytes->``int->``int-> Unix.msg_flaglist``-> int
valsend_substring :Unix.file_descr ->``string->``int->``int-> Unix.msg_flaglist``-> int
valsendto :Unix.file_descr ->``bytes->``int->``int-> Unix.msg_flaglist``-> Unix.sockaddr -> int
valsendto_substring :Unix.file_descr ->``string->``int->``int-> Unix.msg_flaglist``-> Unix.sockaddr -> int
valopen_connection :Unix.sockaddr -> in_channel*out_channel