-
Notifications
You must be signed in to change notification settings - Fork 13
/
websocketaf.mli
267 lines (202 loc) · 5.58 KB
/
websocketaf.mli
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
module IOVec = Httpaf.IOVec
module Payload : sig
type t
val is_closed : t -> bool
val schedule_read :
t ->
on_eof:(unit -> unit) ->
on_read:(Bigstringaf.t -> off:int -> len:int -> unit) ->
unit
val close : t -> unit
end
module Websocket : sig
module Opcode : sig
type standard_non_control =
[ `Continuation
| `Text
| `Binary ]
type standard_control =
[ `Connection_close
| `Ping
| `Pong ]
type standard =
[ standard_non_control
| standard_control ]
type t =
[ standard
| `Other of int ]
val code : t -> int
val of_code : int -> t option
val of_code_exn : int -> t
val to_int : t -> int
val of_int : int -> t option
val of_int_exn : int -> t
val pp_hum : Format.formatter -> t -> unit
end
module Close_code : sig
type standard =
[ `Normal_closure
| `Going_away
| `Protocol_error
| `Unsupported_data
| `No_status_rcvd
| `Abnormal_closure
| `Invalid_frame_payload_data
| `Policy_violation
| `Message_too_big
| `Mandatory_ext
| `Internal_server_error
| `TLS_handshake ]
type t =
[ standard | `Other of int ]
val code : t -> int
val of_code : int -> t option
val of_code_exn : int -> t
val to_int : t -> int
val of_int : int -> t option
val of_int_exn : int -> t
end
module Frame : sig
type t
val is_fin : t -> bool
val rsv : t -> int
val opcode : t -> Opcode.t
val has_mask : t -> bool
val mask : t -> int32 option
val mask_exn : t -> int32
val payload : t -> Payload.t
val payload_length : t -> int
val length : t -> int
val parse : buf:Bigstringaf.t -> t Angstrom.t
val payload_parser : t -> unit Angstrom.t
val serialize_control : ?mask:int32 -> Faraday.t -> opcode:Opcode.standard_control -> unit
val schedule_serialize
: ?mask:int32
-> Faraday.t
-> is_fin:bool
-> opcode:Opcode.t
-> payload:Bigstringaf.t
-> off:int
-> len:int
-> unit
val serialize_bytes
: ?mask:int32
-> Faraday.t
-> is_fin:bool
-> opcode:Opcode.t
-> payload:Bytes.t
-> off:int
-> len:int
-> unit
end
end
module Wsd : sig
type mode =
[ `Client of unit -> int32
| `Server
]
type t
val create
: mode
-> t
val schedule
: t
-> kind:[ `Text | `Binary | `Continuation ]
-> Bigstringaf.t
-> off:int
-> len:int
-> unit
val send_bytes
: t
-> kind:[ `Text | `Binary | `Continuation ]
-> Bytes.t
-> off:int
-> len:int
-> unit
val send_ping : t -> unit
val send_pong : t -> unit
val flushed : t -> (unit -> unit) -> unit
val close : ?code:Websocket.Close_code.t -> t -> unit
val is_closed : t -> bool
end
module Handshake : sig
val create_request
: nonce:string
-> headers:Httpaf.Headers.t
-> string
-> Httpaf.Request.t
val upgrade_headers
: sha1:(string -> string)
-> request_method:Httpaf.Method.t
-> Httpaf.Headers.t
-> ((string * string) list, string) result
val respond_with_upgrade
: ?headers:Httpaf.Headers.t
-> sha1:(string -> string)
-> Httpaf.Reqd.t
-> (unit -> unit)
-> (unit, string) result
end
module Client_connection : sig
type t
type error =
[ Httpaf.Client_connection.error
| `Handshake_failure of Httpaf.Response.t * Httpaf.Body.Reader.t ]
type input_handlers =
{ frame : opcode:Websocket.Opcode.t -> is_fin:bool -> len:int -> Payload.t -> unit
; eof : unit -> unit }
val connect
: nonce : string
-> ?headers : Httpaf.Headers.t
-> sha1 : (string -> string)
-> error_handler : (error -> unit)
-> websocket_handler : (Wsd.t -> input_handlers)
-> string
-> t
val create
: ?error_handler:(Wsd.t -> [`Exn of exn] -> unit)
-> (Wsd.t -> input_handlers) -> t
val next_read_operation : t -> [ `Read | `Yield | `Close ]
val next_write_operation
: t
-> [ `Write of Bigstringaf.t IOVec.t list | `Yield | `Close of int ]
val read : t -> Bigstringaf.t -> off:int -> len:int -> int
val read_eof : t -> Bigstringaf.t -> off:int -> len:int -> int
val yield_reader : t -> (unit -> unit) -> unit
val report_write_result : t -> [`Ok of int | `Closed ] -> unit
val yield_writer : t -> (unit -> unit) -> unit
val report_exn : t -> exn -> unit
val is_closed : t -> bool
val shutdown : t -> unit
end
module Server_connection : sig
type t
type input_handlers =
{ frame : opcode:Websocket.Opcode.t -> is_fin:bool -> len:int -> Payload.t -> unit
; eof : unit -> unit }
type error = [ `Exn of exn ]
type error_handler = Wsd.t -> error -> unit
(* TODO: should take handshake error handler. *)
val create
: sha1 : (string -> string)
-> ?error_handler : error_handler
-> (Wsd.t -> input_handlers)
-> t
val create_websocket
: ?error_handler:error_handler
-> (Wsd.t -> input_handlers)
-> t
val next_read_operation : t -> [ `Read | `Yield | `Close ]
val next_write_operation : t -> [
| `Write of Bigstringaf.t IOVec.t list
| `Yield
| `Close of int ]
val read : t -> Bigstringaf.t -> off:int -> len:int -> int
val read_eof : t -> Bigstringaf.t -> off:int -> len:int -> int
val report_write_result : t -> [`Ok of int | `Closed ] -> unit
val report_exn : t -> exn -> unit
val yield_reader : t -> (unit -> unit) -> unit
val yield_writer : t -> (unit -> unit) -> unit
val is_closed : t -> bool
val shutdown : t -> unit
end