-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from inhabitedtype/fix-build
fix the build and start using travis
- Loading branch information
Showing
14 changed files
with
349 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
language: c | ||
sudo: false | ||
services: | ||
- docker | ||
install: wget https://raw.githubusercontent.com/ocaml/ocaml-travisci-skeleton/master/.travis-docker.sh | ||
script: bash -ex ./.travis-docker.sh | ||
env: | ||
global: | ||
- DISTRO="ubuntu" | ||
- PACKAGE="websocketaf" | ||
- TESTS=true | ||
matrix: | ||
- OCAML_VERSION="4.07" | ||
- OCAML_VERSION="4.06" | ||
- OCAML_VERSION="4.05" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# websocketaf | ||
|
||
[![Build Status](https://travis-ci.org/inhabitedtype/websocketaf.svg?branch=master)](https://travis-ci.org/inhabitedtype/websocketaf) | ||
|
||
WIP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,33 @@ | ||
module IOVec = Httpaf.IOVec | ||
|
||
type t | ||
type t | ||
|
||
type error = | ||
[ Httpaf.Client_connection.error | ||
| `Handshake_failure of Httpaf.Request.t * [`read] Httpaf.Body.t ] | ||
| `Handshake_failure of Httpaf.Response.t * [`read] Httpaf.Body.t ] | ||
|
||
type input_handlers = Client_websocket.input_handlers = | ||
{ frame : Websocket.Opcode.t -> is_fin:bool -> Bigstring.t -> off:int -> len:int -> unit | ||
; eof : unit -> unit } | ||
type input_handlers = Client_websocket.input_handlers = | ||
{ frame : opcode:Websocket.Opcode.t -> is_fin:bool -> Bigstringaf.t -> off:int -> len:int -> unit | ||
; eof : unit -> unit } | ||
|
||
val create | ||
val create | ||
: nonce : string | ||
-> host : string | ||
-> port : int | ||
-> resource : string | ||
-> sha1 : (string -> string) | ||
-> error_handler : (Httpaf.Response.t -> [`read] Httpaf.Body.t -> unit) | ||
-> websocket_handler : (Wsd.t -> input_handlers) | ||
-> error_handler : (error -> unit) | ||
-> websocket_handler : (Wsd.t -> input_handlers) | ||
-> t | ||
|
||
val next_read_operation : t -> [ `Read | `Yield | `Close ] | ||
val next_write_operation : t -> [ `Write of Bigstring.t IOVec.t list | `Yield | `Close of int ] | ||
val next_read_operation : t -> [ `Read | `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 read : t -> Bigstring.t -> off:int -> len:int -> int | ||
val report_write_result : t -> [`Ok of int | `Closed ] -> unit | ||
|
||
val yield_reader : t -> (unit -> unit) -> unit | ||
val yield_writer : t -> (unit -> unit) -> unit | ||
|
||
val close : t -> unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,50 @@ | ||
module IOVec = Httpaf.IOVec | ||
include Httpaf.Client_connection | ||
|
||
let create | ||
~nonce | ||
~host | ||
~port | ||
type t = | ||
{ connection : Httpaf.Client_connection.t | ||
; body : [`write] Httpaf.Body.t } | ||
|
||
let create | ||
~nonce | ||
~host | ||
~port | ||
~resource | ||
~error_handler | ||
~response_handler | ||
~response_handler | ||
= | ||
let nonce = Base64.encode_exn nonce in | ||
let headers = | ||
[ "upgrade" , "websocket" | ||
; "connection" , "upgrade" | ||
; "host" , String.concat ":" [ host; string_of_int port ] | ||
; "sec-websocket-version", "13" | ||
; "sec-websocket-version", "13" | ||
; "sec-websocket-key" , nonce | ||
] |> Httpaf.Headers.of_list | ||
in | ||
let request_body, t = | ||
let body, connection = | ||
Httpaf.Client_connection.request | ||
(Httpaf.Request.create ~headers `GET resource) | ||
~error_handler | ||
~response_handler | ||
in | ||
Httpaf.Body.close_writer request_body; | ||
t | ||
{ connection | ||
; body | ||
} | ||
;; | ||
|
||
let next_read_operation t = | ||
Httpaf.Client_connection.next_read_operation t.connection | ||
|
||
let next_write_operation t = | ||
Httpaf.Client_connection.next_write_operation t.connection | ||
|
||
let read t = | ||
Httpaf.Client_connection.read t.connection | ||
|
||
let report_write_result t = | ||
Httpaf.Client_connection.report_write_result t.connection | ||
|
||
let yield_writer t = | ||
Httpaf.Client_connection.yield_writer t.connection | ||
|
||
let close t = | ||
Httpaf.Body.close_writer t.body |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,46 @@ | ||
module IOVec = Httpaf.IOVec | ||
|
||
type t = | ||
{ reader : Reader.t | ||
{ reader : [`Parse of string list * string] Reader.t | ||
; wsd : Wsd.t } | ||
|
||
type input_handlers = | ||
{ frame : Websocket.Opcode.t -> is_fin:bool -> Bigstring.t -> off:int -> len:int -> unit | ||
; eof : unit -> unit } | ||
{ frame : opcode:Websocket.Opcode.t -> is_fin:bool -> Bigstringaf.t -> off:int -> len:int -> unit | ||
; eof : unit -> unit } | ||
|
||
let random_int32 () = | ||
Random.int32 Int32.max_int | ||
|
||
let create ~websocket_handler = | ||
let wsd = Wsd.create () in | ||
let { frame; eof } = websocket_handler wsd in | ||
let mode = `Client random_int32 in | ||
let wsd = Wsd.create mode in | ||
let { frame; _ } = websocket_handler wsd in | ||
{ reader = Reader.create frame | ||
; wds | ||
; wsd | ||
} | ||
|
||
let next_read_operation t = | ||
Reader.next t.reader | ||
|
||
let next_write_operation t = | ||
Wsd.next t.wsd | ||
|
||
let read t bs ~off ~len = | ||
Reader.read_with_more t.reader bs ~off ~len Incomplete | ||
|
||
let read_eof t bs ~off ~len = | ||
Reader.read_with_more t.reader bs ~off ~len Complete | ||
|
||
let report_write_result t result = | ||
Wsd.report_result t.wsd result | ||
|
||
let yield_writer t k = | ||
if Wsd.is_closed t.wsd | ||
then begin | ||
Wsd.close t.wsd; | ||
k () | ||
end else | ||
Wsd.when_ready_to_write t.wsd k | ||
|
||
let close { wsd; _ } = | ||
Wsd.close wsd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.