package dream-httpaf
Internal: shared http/af stack for Dream (server) and Hyper (client)
Install
Dune Dependency
Authors
Maintainers
Sources
dream-1.0.0-alpha6.tar.gz
sha256=8d3b6344c0e175aca628b3d5bb8ee58265e8c1074fc2d40d63f136fef83daf90
doc/src/dream-httpaf.dream-websocketaf/wsd.ml.html
Source file wsd.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
module Httpaf = Dream_httpaf_.Httpaf module IOVec = Httpaf.IOVec type error = [ `Exn of exn ] type mode = [ `Client of unit -> int32 | `Server ] type t = { faraday : Faraday.t ; mode : mode ; mutable wakeup : Optional_thunk.t ; error_handler: error_handler ; mutable error_code: [`Ok | error ] } and error_handler = t -> error -> unit let default_ready_to_write = Sys.opaque_identity (fun () -> ()) let create ~error_handler mode = { faraday = Faraday.create 0x1000 ; mode ; wakeup = Optional_thunk.none ; error_handler ; error_code = `Ok } let mask t = match t.mode with | `Client m -> Some (m ()) | `Server -> None let is_closed t = Faraday.is_closed t.faraday let on_wakeup t k = if Faraday.is_closed t.faraday then failwith "on_wakeup on closed writer" else if Optional_thunk.is_some t.wakeup then failwith "on_wakeup: only one callback can be registered at a time" else t.wakeup <- Optional_thunk.some k let wakeup t = let f = t.wakeup in t.wakeup <- Optional_thunk.none; Optional_thunk.call_if_some f let schedule t ?(is_fin=true) ~kind payload ~off ~len = let mask = mask t in Serialize.schedule_serialize t.faraday (* TODO: is_fin *) ?mask ~is_fin ~opcode:(kind :> Websocket.Opcode.t) ~src_off:0 ~payload ~off ~len; wakeup t let send_bytes t ?(is_fin=true) ~kind payload ~off ~len = let mask = mask t in Serialize.serialize_bytes t.faraday ?mask ~is_fin ~opcode:(kind :> Websocket.Opcode.t) ~payload ~src_off:0 ~off ~len; wakeup t let send_ping ?application_data t = begin match application_data with | None -> Serialize.serialize_control t.faraday ~opcode:`Ping | Some { IOVec.buffer; off; len } -> let mask = mask t in Serialize.schedule_serialize t.faraday ?mask ~is_fin:true ~opcode:`Ping ~src_off:0 ~payload:buffer ~off ~len; end; wakeup t let send_pong ?application_data t = begin match application_data with | None -> Serialize.serialize_control t.faraday ~opcode:`Pong; | Some { IOVec.buffer; off; len } -> let mask = mask t in Serialize.schedule_serialize t.faraday ?mask ~is_fin:true ~opcode:`Pong ~src_off:0 ~payload:buffer ~off ~len; end; wakeup t let flushed t f = Faraday.flush t.faraday f let close ?code t = begin match code with | Some code -> let mask = mask t in let payload = Bytes.create 2 in Bytes.set_uint16_be payload 0 (Websocket.Close_code.to_int code); Serialize.serialize_bytes t.faraday ?mask ~is_fin:true ~opcode:`Connection_close ~src_off:0 ~payload ~off:0 ~len:2; | None -> () end; Faraday.close t.faraday; wakeup t let error_code t = match t.error_code with | #error as error -> Some error | `Ok -> None let report_error t error = match t.error_code with | `Ok -> t.error_code <- (error :> [`Ok | error]); if not (is_closed t) then t.error_handler t error | `Exn _exn -> close ~code:`Abnormal_closure t let next t = match Faraday.operation t.faraday with | `Close -> `Close 0 (* XXX(andreas): should track unwritten bytes *) | `Yield -> `Yield | `Writev iovecs -> `Write iovecs let report_result t result = match result with | `Closed -> close t | `Ok len -> Faraday.shift t.faraday len
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>