package async_unix

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file async_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
module Async_config = Config
module Busy_poller = Busy_poller
module Clock = Clock
module Dump_core_on_job_delay = Dump_core_on_job_delay
module Fd = Fd
module In_thread = In_thread
module Io_stats = Io_stats
module Io_uring_raw = Io_uring_raw
module Io_uring_raw_singleton = Io_uring_raw_singleton
module Io_uring = Io_uring
module Print = Async_print
module Process = Process
module Reader = Reader
module Require_explicit_time_source = Require_explicit_time_source
module Scheduler = Scheduler
module Shutdown = Shutdown
module Signal = Signal
module Socket = Unix_syscalls.Socket
module Sys = Async_sys
module Tcp = Tcp
module Thread_safe = Thread_safe
module Writer = Writer

module Unix = struct
  module Fd = Fd

  include Unix_syscalls (** @open *)
end

let after = Clock.after
let at = Clock.at
let every = Clock.every
let with_timeout = Clock.with_timeout
let schedule = Scheduler.schedule
let schedule' = Scheduler.schedule'
let shutdown = Shutdown.shutdown
let within = Scheduler.within
let within' = Scheduler.within'

(* We rebind all pervasive and some Core functions that deal with I/O so that one
   doesn't unintentionally do blocking stuff in an Async program. *)

(** Shadow blocking functions in [Core.Printf] to prevent their unintentional use. *)
module Printf = struct
  let _shadow = `Probably_should_not_use_blocking_Core_Printf_functions_with_Async
  let bprintf = Core.Printf.bprintf
  let eprintf = _shadow
  let exitf = _shadow
  let failwithf = Core.Printf.failwithf
  let fprintf _ = _shadow
  let ifprintf _ = Core.Printf.ifprintf
  let invalid_argf = Core.Printf.invalid_argf
  let kbprintf = Core.Printf.kbprintf
  let kfprintf _ _ = _shadow
  let ksprintf = Core.Printf.ksprintf
  let printf = _shadow
  let sprintf = Core.Printf.sprintf
end

include struct
  open Core

  module Overwrite_ = struct
    let overwrite1 (`This_is_async__Think_about_blocking as x) = x
    let overwrite2 `This_is_async__Think_about_blocking = overwrite1
    let overwrite3 `This_is_async__Think_about_blocking = overwrite2
    let overwrite4 `This_is_async__Think_about_blocking = overwrite3
  end

  open Overwrite_

  let close_in_noerr = overwrite1
  let close_in = overwrite1
  let close_out_noerr = overwrite1
  let close_out = overwrite1
  let eprintf = Print.eprintf
  let flush_all = overwrite1
  let flush = overwrite1
  let fprintf = Print.fprintf
  let ifprintf = Printf.ifprintf
  let in_channel_length = overwrite1
  let input_binary_int = overwrite1
  let input_byte = overwrite1
  let input_char = overwrite1
  let input_line = overwrite1
  let input_lines ?fix_win_eol:_ = overwrite1
  let input = overwrite4
  let input_value = overwrite1
  let open_in_bin = overwrite1
  let open_in_gen = overwrite3
  let open_in = overwrite1
  let open_out_bin = overwrite1
  let open_out_gen = overwrite3
  let open_out = overwrite1
  let out_channel_length = overwrite1
  let output_binary_int = overwrite2
  let output_byte = overwrite2
  let output_char = overwrite2
  let output = overwrite4
  let output_string = overwrite2
  let output_value = overwrite2
  let pos_in = overwrite1
  let pos_out = overwrite1
  let prerr_char = Print.prerr_char
  let prerr_endline = Print.prerr_endline
  let prerr_float = Print.prerr_float
  let prerr_int = Print.prerr_int
  let prerr_newline = Print.prerr_newline
  let prerr_string = Print.prerr_string
  let print_char = Print.print_char
  let print_endline = Print.print_endline
  let print_float = Print.print_float
  let printf = Print.printf
  let print_int = Print.print_int
  let print_newline = Print.print_newline
  let print_s = Print.print_s
  let print_string = Print.print_string
  let read_float = overwrite1
  let read_int = overwrite1
  let read_line = overwrite1
  let read_lines = overwrite1
  let read_wrap ?binary:_ ~f:_ = overwrite1
  let really_input = overwrite4
  let seek_in = overwrite2
  let seek_out = overwrite1
  let set_binary_mode_in = overwrite2
  let set_binary_mode_out = overwrite2
  let write_lines = overwrite2
  let write_wrap ?binary:_ ~f:_ = overwrite1

  let (eprint_s [@deprecated
                  "[since 2019-12] If you want to the blocking version, use \
                   [Core.eprint_s] (this preserves behavior, but is discouraged). If you \
                   want the nonblocking version, use [eprint_s_nonblocking] or \
                   [Print.eprint_s]"])
    =
    overwrite1
  ;;

  let eprint_s_nonblocking = Print.eprint_s

  module LargeFile = struct
    let seek_out = overwrite1
    let pos_out = overwrite1
    let out_channel_length = overwrite1
    let seek_in = overwrite1
    let pos_in = overwrite1
    let in_channel_length = overwrite1
  end

  module Sexp : sig
    include module type of struct
      include Sexp
    end

    val save : ?perm:int -> string -> t -> unit
      [@@alert blocking "Use [Writer.save_sexp ~hum:false] to avoid blocking."]

    val save_hum : ?perm:int -> string -> t -> unit
      [@@alert blocking "Use [Writer.save_sexp ~hum:true] to avoid blocking."]

    val save_mach : ?perm:int -> string -> t -> unit
      [@@alert blocking "Use [Writer.save_sexp ~hum:false] to avoid blocking."]

    val save_sexps : ?perm:int -> string -> t list -> unit
      [@@alert blocking "Use [Writer.save_sexps ~hum:false] to avoid blocking."]

    val save_sexps_hum : ?perm:int -> string -> t list -> unit
      [@@alert blocking "Use [Writer.save_sexps ~hum:true] to avoid blocking."]

    val save_sexps_mach : ?perm:int -> string -> t list -> unit
      [@@alert blocking "Use [Writer.save_sexps ~hum:false] to avoid blocking."]
  end =
    Sexp
end

let exit = Shutdown.exit

(**/**)

module Async_unix_private = struct
  module By_descr = By_descr
  module Raw_fd = Raw_fd
  module Raw_scheduler = Raw_scheduler
  module Syscall = Syscall
end