package httpcats

  1. Overview
  2. Docs

Source file http_miou_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
let src = Logs.Src.create "http-miou-unix"

module Log = (val Logs.src_log src : Logs.LOG)

external reraise : exn -> 'a = "%reraise"

module TCP = struct
  type t = Miou_unix.file_descr

  let read flow ?off ?len buf =
    try Miou_unix.read flow buf ?off ?len with
    | Unix.Unix_error (Unix.ECONNRESET, _, _) -> 0
    | Unix.Unix_error _ as exn -> raise exn

  let write fd ?off ?len str =
    try Miou_unix.write fd str ?off ?len with
    | Unix.(Unix_error (EPIPE, _, _)) -> reraise Flow.Closed_by_peer
    | exn -> reraise exn

  let close = Miou_unix.close

  let shutdown flow cmd =
    try match cmd with
      | `read -> Unix.shutdown (Miou_unix.to_file_descr flow) Unix.SHUTDOWN_RECEIVE
      | `write -> Unix.shutdown (Miou_unix.to_file_descr flow) Unix.SHUTDOWN_SEND
      | `read_write -> Unix.close (Miou_unix.to_file_descr flow)
    with Unix.Unix_error (Unix.ENOTCONN, _, _) -> ()
  [@@ocamlformat "disable"]
end

module TLS = struct
  include Tls_miou_unix

  let write fd ?off ?len str =
    try write fd ?off ?len str with
    | Tls_miou_unix.Closed_by_peer -> reraise Flow.Closed_by_peer
    | exn -> reraise exn
end
OCaml

Innovation. Community. Security.