~nickbp/tokio-scgi

7ae850993189639a89eda0570ce331873e2f8ed9 — Nick Parker 2 years ago 3761ca5
Switch examples to async/await

TODO figure out read looping
6 files changed, 289 insertions(+), 339 deletions(-)

M Cargo.lock
M Cargo.toml
M examples/client.rs
M examples/server.rs
D src/abortable_stream.rs
M src/lib.rs
M Cargo.lock => Cargo.lock +202 -104
@@ 59,6 59,14 @@ dependencies = [
]

[[package]]
name = "crossbeam-channel"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "crossbeam-deque"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 122,11 130,30 @@ version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "futures"
version = "0.1.27"
name = "futures-core-preview"
version = "0.3.0-alpha.17"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "futures-sink-preview"
version = "0.3.0-alpha.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "futures-core-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "futures-util-preview"
version = "0.3.0-alpha.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "futures-core-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures-sink-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
 "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)",
 "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "iovec"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 156,11 183,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "lock_api"
version = "0.1.5"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
 "scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]


@@ 172,6 198,11 @@ dependencies = [
]

[[package]]
name = "memchr"
version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "memoffset"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 246,35 277,43 @@ dependencies = [
]

[[package]]
name = "owning_ref"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "parking_lot"
version = "0.7.1"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
 "parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "lock_api 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
 "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "parking_lot_core"
version = "0.4.0"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
 "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
 "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)",
 "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
 "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)",
 "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
 "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
 "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "pin-utils"
version = "0.1.0-alpha.4"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "proc-macro2"
version = "0.4.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "proptest"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 299,6 338,14 @@ version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "quote"
version = "0.6.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "rand"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 448,6 495,11 @@ version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "scopeguard"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 471,9 523,14 @@ version = "0.6.10"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "stable_deref_trait"
version = "1.1.1"
name = "syn"
version = "0.15.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
 "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
 "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "tempfile"


@@ 490,91 547,104 @@ dependencies = [

[[package]]
name = "tokio"
version = "0.1.22"
version = "0.2.0-alpha.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
 "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures-core-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures-sink-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures-util-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
 "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-fs 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-sync 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-threadpool 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-codec 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-current-thread 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-executor 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-fs 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-io 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-macros 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-reactor 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-sync 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-tcp 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-threadpool 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-timer 0.3.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-udp 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-uds 0.3.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tracing-core 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "tokio-codec"
version = "0.1.1"
version = "0.2.0-alpha.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures-core-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures-sink-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-io 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "tokio-current-thread"
version = "0.1.6"
version = "0.2.0-alpha.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
 "crossbeam-channel 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-executor 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "tokio-executor"
version = "0.1.7"
version = "0.2.0-alpha.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "tokio-fs"
version = "0.1.6"
version = "0.2.0-alpha.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-threadpool 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures-core-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures-util-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-io 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-threadpool 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "tokio-io"
version = "0.1.12"
version = "0.2.0-alpha.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures-core-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
 "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "tokio-macros"
version = "0.2.0-alpha.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
 "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
 "syn 0.15.43 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "tokio-reactor"
version = "0.1.9"
version = "0.2.0-alpha.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures-core-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
 "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
 "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)",
 "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-sync 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-executor 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-io 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-sync 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]


@@ 583,89 653,102 @@ version = "0.1.0"
dependencies = [
 "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
 "proptest 0.9.4 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-sync 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-codec 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "tokio-sync"
version = "0.1.6"
version = "0.2.0-alpha.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures-core-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures-sink-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures-util-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "tokio-tcp"
version = "0.1.3"
version = "0.2.0-alpha.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures-core-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures-util-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
 "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
 "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-io 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-reactor 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "tokio-threadpool"
version = "0.1.14"
version = "0.2.0-alpha.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
 "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures-core-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures-util-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
 "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
 "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
 "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-executor 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-sync 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "tokio-timer"
version = "0.2.11"
version = "0.3.0-alpha.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures-core-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures-util-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
 "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-executor 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-sync 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "tokio-udp"
version = "0.1.3"
version = "0.2.0-alpha.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures-core-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures-util-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
 "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-reactor 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "tokio-uds"
version = "0.2.5"
version = "0.3.0-alpha.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures-core-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
 "futures-util-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)",
 "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
 "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)",
 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
 "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)",
 "mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-codec 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-io 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "tokio-reactor 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "tracing-core"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]


@@ 674,6 757,11 @@ version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "unicode-xid"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "wait-timeout"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 729,6 817,7 @@ dependencies = [
"checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c"
"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33"
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
"checksum crossbeam-channel 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c8ec7fcd21571dc78f96cc96243cab8d8f035247c3efd16c687be154c3fa9efa"
"checksum crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b18cd2e169ad86297e6bc0ad9aa679aee9daa4f19e8163860faf7c164e4f5a71"
"checksum crossbeam-epoch 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "04c9e3102cc2d69cd681412141b390abd55a362afc1540965dad0ad4d34280b4"
"checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b"


@@ 737,13 826,16 @@ dependencies = [
"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
"checksum futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)" = "a2037ec1c6c1c4f79557762eab1f7eae1f64f6cb418ace90fae88f0942b60139"
"checksum futures-core-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)" = "4b141ccf9b7601ef987f36f1c0d9522f76df3bba1cf2e63bfacccc044c4558f5"
"checksum futures-sink-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)" = "4309a25a1069a1f3c10647b227b9afe6722b67a030d3f00a9cbdc171fc038de4"
"checksum futures-util-preview 0.3.0-alpha.17 (registry+https://github.com/rust-lang/crates.io-index)" = "af8198c48b222f02326940ce2b3aa9e6e91a32886eeaad7ca3b8e4c70daa3f4e"
"checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
"checksum libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)" = "6281b86796ba5e4366000be6e9e18bf35580adf9e63fbe2294aadb587613a319"
"checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c"
"checksum lock_api 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f8912e782533a93a167888781b836336a6ca5da6175c05944c86cf28c31104dc"
"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6"
"checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e"
"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3"
"checksum mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)" = "83f51996a3ed004ef184e16818edc51fadffe8e7ca68be67f9dee67d84d0ff23"
"checksum mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125"


@@ 752,11 844,13 @@ dependencies = [
"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945"
"checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32"
"checksum num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcef43580c035376c0705c42792c294b66974abbfd2789b511784023f71f3273"
"checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13"
"checksum parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337"
"checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9"
"checksum parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252"
"checksum parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b"
"checksum pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5894c618ce612a3fa23881b152b608bafb8c56cfc22f434a3ba3120b40f7b587"
"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
"checksum proptest 0.9.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cf147e022eacf0c8a054ab864914a7602618adba841d800a9a9868a5237a529f"
"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0"
"checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
"checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca"
"checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef"
"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"


@@ 774,26 868,30 @@ dependencies = [
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
"checksum rusty-fork 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3dd93264e10c577503e926bd1430193eeb5d21b059148910082245309b424fae"
"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
"checksum scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d"
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
"checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7"
"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
"checksum syn 0.15.43 (registry+https://github.com/rust-lang/crates.io-index)" = "ee06ea4b620ab59a2267c6b48be16244a3389f8bfa0986bdd15c35b890b00af3"
"checksum tempfile 3.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7dc4738f2e68ed2855de5ac9cdbe05c9216773ecde4739b2f095002ab03a13ef"
"checksum tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)" = "5a09c0b5bb588872ab2f09afa13ee6e9dac11e10a0ec9e8e3ba39a5a5d530af6"
"checksum tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5c501eceaf96f0e1793cf26beb63da3d11c738c4a943fdf3746d81d64684c39f"
"checksum tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d16217cad7f1b840c5a97dfb3c43b0c871fef423a6e8d2118c604e843662a443"
"checksum tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "83ea44c6c0773cc034771693711c35c677b4b5a4b21b9e7071704c54de7d555e"
"checksum tokio-fs 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe6dc22b08d6993916647d108a1a7d15b9cd29c4f4496c62b92c45b5041b7af"
"checksum tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "5090db468dad16e1a7a54c8c67280c5e4b544f3d3e018f0b913b400261f85926"
"checksum tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "6af16bfac7e112bea8b0442542161bfc41cbfa4466b580bdda7d18cb88b911ce"
"checksum tokio-sync 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2162248ff317e2bc713b261f242b69dbb838b85248ed20bb21df56d60ea4cae7"
"checksum tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1d14b10654be682ac43efee27401d792507e30fd8d26389e1da3b185de2e4119"
"checksum tokio-threadpool 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "72558af20be886ea124595ea0f806dd5703b8958e4705429dd58b3d8231f72f2"
"checksum tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "f2106812d500ed25a4f38235b9cae8f78a09edf43203e16e59c3b769a342a60e"
"checksum tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "66268575b80f4a4a710ef83d087fdfeeabdce9b74c797535fbac18a2cb906e92"
"checksum tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "037ffc3ba0e12a0ab4aca92e5234e0dedeb48fddf6ccd260f1f150a36a9f2445"
"checksum tokio 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6320d5796f0e08444252f37de1e23dab529e6f7e662447a0e10e183d1cbda371"
"checksum tokio-codec 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)" = "60505acba66c2b46c475b682355967e270db2c0a200392ca2079d214f514935e"
"checksum tokio-current-thread 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ed30983efe64aa01758777622d70f45054802d959f02b7895b7245883699487"
"checksum tokio-executor 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1e0937fcedb52baa1424b7483977ec1e387a75413c12abc232c3c092ed35f68d"
"checksum tokio-fs 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1e96beb64c2b41f4a04b9a6f6834684b9582b3a75534279e6f93b6f91b163eac"
"checksum tokio-io 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab1e0e025bd8193899c064a0b03d68bf7d599aaf6c4c2a62aa394bb0e476c1f7"
"checksum tokio-macros 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)" = "04da794609e1785ae8541a596891641897ae4693bb451cd1c91cd8ce965b36e6"
"checksum tokio-reactor 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aea2939bfb43f47226624d08486855f022c015016f599bf541d85c28557efccc"
"checksum tokio-sync 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ce3e512e9a367074a2a73fc2b48641e672eb572880b4e9c1eb01e7d1539f9694"
"checksum tokio-tcp 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e309cd85bf33849dd29cb4dbdcfaf087bc6ae69a58ba37a9c39d8457ee706a6"
"checksum tokio-threadpool 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2c3bb6766294ff0348ace4542ff49a4e2e951ffb54a3f90dcf060826fee499"
"checksum tokio-timer 0.3.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)" = "45d6916b534f98c7a8a91bb4ecb6cc5f8d883d4025f67c856ef7fd21d78dc7b2"
"checksum tokio-udp 0.2.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f5e5e75ef9cddcc615b2499be3d3c223a3c426c2d7eaa6969c55ac3f63e1fd10"
"checksum tokio-uds 0.3.0-alpha.1 (registry+https://github.com/rust-lang/crates.io-index)" = "92a2aae41c36e1b2f8ff3fb3e518118ad2910214d97d706fc6c950b2da9430da"
"checksum tracing-core 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0be9bdf75dce384e15ff6cfd00898b967de1598a55a4236a6b9bc06444fbc6ba"
"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum wait-timeout 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6"
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770"

M Cargo.toml => Cargo.toml +2 -3
@@ 9,10 9,9 @@ description = "Tokio codec for building and parsing SCGI requests"
repository = "https://github.com/nickbp/tokio-scgi"

[dependencies]
tokio = "0.1.22"
tokio-codec = "0.1.1"
tokio = "=0.2.0-alpha.1"
tokio-codec = "=0.2.0-alpha.1"
bytes = "0.4.12"

[dev-dependencies]
proptest = "0.9.4"
tokio-sync = "0.1.6"

M examples/client.rs => examples/client.rs +26 -79
@@ 1,4 1,5 @@
#![deny(warnings, rust_2018_idioms)]
#![feature(async_await)]

use bytes::{BufMut, BytesMut};
use std::env;


@@ 9,8 10,6 @@ use tokio::net::{TcpStream, UnixStream};
use tokio::prelude::*;
use tokio_codec::Framed;
use tokio_scgi::client::{SCGICodec, SCGIRequest};
use tokio_sync::oneshot;
use tokio_sync::oneshot::Sender;

fn syntax() -> Error {
    println!(


@@ 20,7 19,8 @@ fn syntax() -> Error {
    Error::new(ErrorKind::InvalidInput, "Missing required argument")
}

fn main() -> Result<(), Error> {
#[tokio::main]
async fn main() -> Result<(), Error> {
    if env::args().len() <= 1 {
        return Err(syntax());
    }


@@ 29,15 29,12 @@ fn main() -> Result<(), Error> {
        // Probably a commandline argument like '-h'/'--help', avoid parsing as a hostname
        return Err(syntax());
    }

    // Create a channel which will be provided the response by the async callbacks once it's arrived.
    // Meanwhile we wait for the response on this end of things.
    let (sender, receiver) = oneshot::channel::<Option<BytesMut>>();
    if endpoint.contains('/') {
        // Probably a path to a file, assume the argument is a unix socket
        let addr = Path::new(&endpoint);
        println!("Connecting to {}", addr.display());
        connect(UnixStream::connect(&addr), sender);
        let mut conn = UnixStream::connect(&addr).await?;
        run_client(&mut conn).await
    } else {
        // Probably a TCP endpoint, try to resolve it in case it's a hostname
        let addr = endpoint


@@ 46,87 43,37 @@ fn main() -> Result<(), Error> {
            .next()
            .unwrap();
        println!("Connecting to {}", addr);
        connect(TcpStream::connect(&addr), sender);
        let mut conn = TcpStream::connect(&addr).await?;
        run_client(&mut conn).await
    }
}

/// Runs the client: Sends a request and prints the responses via the provided UDS or TCP connection.
async fn run_client<C>(conn: &mut C) -> Result<(), Error>
where C: AsyncRead + AsyncWrite + std::marker::Send + std::marker::Unpin + std::fmt::Debug {
    let (mut tx_scgi, rx_scgi) = Framed::new(conn, SCGICodec::new()).split();

    // Wait for the callbacks to get the response and provide it to the channel.
    match receiver.wait() {
        Ok(Some(response)) => {
    // Send request
    tx_scgi.send(build_request()).await?;

    // Consume response
    // TODO support looping over multiple response calls?
    match rx_scgi.into_future().await {
        (None, _) => Err(Error::new(ErrorKind::Other, "No response received")),
        (Some(Err(e)), _) => Err(Error::new(
            ErrorKind::Other,
            format!("Error when waiting for query result: {}", e),
        )),
        (Some(Ok(response)), _) => {
            match String::from_utf8(response.to_vec()) {
                Ok(s) => println!("Got {} bytes:\n{}", response.len(), s),
                Err(e) => println!("{} byte response is not UTF8 ({}):\n{:?}", response.len(), e, response)
            }
            Ok(())
        }
        Ok(None) => Err(Error::new(ErrorKind::Other, "No response received")),
        Err(e) => Err(Error::new(
            ErrorKind::Other,
            format!("Error when waiting for query result: {}", e),
        )),
        },
    }
}

/// Schedules a `send()` call to be triggered after the connection is made.
fn connect<C, F>(connect_future: F, output: Sender<Option<BytesMut>>)
where
    C: AsyncRead + AsyncWrite + std::marker::Send + std::fmt::Debug + 'static,
    F: Future<Item = C, Error = Error> + std::marker::Send + 'static,
{
    let cb = connect_future
        .map_err(|e| {
            println!("connect error = {:?}", e);
            //output.send(None);
        })
        .and_then(move |conn| {
            send(conn, output);
            Ok(())
        });
    // The first one in the chain must use tokio::run.
    // tokio::spawn can only be called inside the runtime.
    tokio::run(cb);
}

/// Schedules sending the request payload. Once the send is complete, `recv()` is called for
/// handling the response.
fn send<C>(conn: C, output: Sender<Option<BytesMut>>)
where
    C: AsyncRead + AsyncWrite + std::marker::Send + std::fmt::Debug + 'static,
{
    let (tx_scgi, rx_scgi) = Framed::new(conn, SCGICodec::new()).split();
    let cb = tx_scgi
        .send(build_request())
        .map_err(|e| {
            println!("send error = {:?}", e);
            //output.send(None);
        })
        .and_then(move |_| {
            recv(rx_scgi, output);
            Ok(())
        });
    tokio::spawn(cb);
}

/// Schedules receiving the response. In this demo the response is printed to the console.
fn recv<R>(rx_scgi: R, output: Sender<Option<BytesMut>>)
where
    R: Stream<Item = BytesMut, Error = Error> + std::marker::Send + std::fmt::Debug + 'static,
{
    // TODO repeatedly recv until disconnected by server?
    let cb = rx_scgi
        .into_future()
        .map_err(|e| {
            println!("recv error = {:?}", e);
            //output.send(None);
        })
        .and_then(move |(response, _stream)| {
            if let Err(_response) = output.send(response) {
                println!("Failed to send response");
            }
            Ok(())
        });
    tokio::spawn(cb);
}

fn build_request() -> SCGIRequest {
    let content_str = b"{\"description\": \"my name is also bort <><><>\"}";
    let mut content = BytesMut::with_capacity(content_str.len());

M examples/server.rs => examples/server.rs +59 -72
@@ 1,4 1,5 @@
#![deny(warnings, rust_2018_idioms)]
#![feature(async_await)]

use bytes::{BufMut, BytesMut};
use std::env;


@@ 11,7 12,6 @@ use tokio;
use tokio::net::{TcpListener, UnixListener};
use tokio::prelude::*;
use tokio_codec::Framed;
use tokio_scgi::abortable_stream::{AbortableItem, AbortableStream};
use tokio_scgi::server::{SCGICodec, SCGIRequest};

fn syntax() -> Error {


@@ 22,7 22,8 @@ fn syntax() -> Error {
    Error::new(ErrorKind::InvalidInput, "Missing required argument")
}

fn main() -> Result<(), Error> {
#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
    if env::args().len() <= 1 {
        return Err(syntax());
    }


@@ 34,22 35,29 @@ fn main() -> Result<(), Error> {

    if endpoint.contains('/') {
        // Probably a path to a file, assume the argument is a unix socket
        tokio::run(
            unix_init(endpoint)?
                .incoming()
                .map_err(|e| println!("Unix socket failed: {:?}", e))
                .for_each(|conn| serve(conn)),
        );
        let mut bind = unix_init(endpoint)?;
        loop {
            let (conn, _addr) = bind.accept().await?;
            tokio::spawn(async move {
                match serve(conn).await {
                    Err(e) =>{ println!("Error serving UDS session: {:?}", e); }
                    Ok(()) => { println!("Served UDS request"); }
                };
            });
        }
    } else {
        // Probably a TCP endpoint, try to resolve it in case it's a hostname
        tokio::run(
            tcp_init(endpoint)?
                .incoming()
                .map_err(|e| println!("TCP socket failed: {:?}", e))
                .for_each(|conn| serve(conn)),
        );
        let mut bind = tcp_init(endpoint)?;
        loop {
            let (conn, addr) = bind.accept().await?;
            tokio::spawn(async move {
                match serve(conn).await {
                    Err(e) => { println!("Error when serving TCP session from {:?}: {:?}", addr, e); }
                    Ok(()) => { println!("Served TCP request from {:?}", addr); }
                };
            });
        }
    }
    Ok(())
}

fn unix_init(path_str: String) -> Result<UnixListener, Error> {


@@ 108,52 116,35 @@ macro_rules! http_response {
    };
}

fn serve<T>(conn: T) -> tokio::executor::Spawn
where
    T: AsyncRead + AsyncWrite + 'static + std::marker::Send + std::fmt::Debug,
{
async fn serve<C>(conn: C) -> Result<(), Error>
where C: AsyncRead + AsyncWrite + std::marker::Send + std::marker::Unpin + std::fmt::Debug {
    let mut handler = SampleHandler::new();
    let (tx_scgi, rx_scgi) = Framed::new(conn, SCGICodec::new()).split();
    // Request flow:
    // 1. rx_scgi is queried for request data. It blocks until data is available.
    // 2. The raw request data is received and passed to SCGICodec. which consumes it and returns
    //    an SCGI Request or BodyFragment when enough of the raw data has arrived
    // 3. SCGICodec consumes the raw request data, and waits for at least the complete SCGI headers.
    //    At this point SCGICodec will return a Request, followed by zero or more BodyFragments as
    //    any more raw request data comes in.
    // 4. The Request and any BodyFragments are passed to sample handler, which then returns a
    //    response.
    // 5. Sample handler returns Continue or Stop with its response data, which can be an empty vec.
    // 6. In both Continue and Stop cases, the returned response data is sent back to the client
    //    as-is using tx_scgi. In this direction the SCGICodec functions as a passthrough.
    // 7a. If Stop was returned, a bit is set to ensure that the stream returns None the next time
    //     it's polled. In particular it will avoid reading from rx_scgi again, since sample handler
    //     has effectively said there's nothing left to be read from there.
    // 7b. If Continue was returned, rx_scgi is queried for more data and the cycle continues.
    let session = tx_scgi
        .send_all(AbortableStream::with_err_conv(
            rx_scgi.and_then(move |request| match handler.handle(request) {
                Ok(r) => Ok(r),
                Err(e) => Ok(AbortableItem::Stop(handle_error(e))),
            }),
            // We don't see errors produced by the SCGICodec itself, so we give AbortableStream this
            // custom error handler to turn any parsing errors into nice HTML responses:
            |err| Some(handle_error(err)),
        ))
        .then(|send_all_result| {
            match send_all_result {
                Ok(_session) => {
                    // Session ended successfully
                    Ok(())
                }
                Err(e) => {
                    println!("Unhandled session error: {:?}", e);
                    // Keep spawn() typing happy:
                    Err(())
                }
            }
        });
    tokio::spawn(session)
    let (mut tx_scgi, rx_scgi) = Framed::new(conn, SCGICodec::new()).split();
    match rx_scgi.into_future().await {
        (None, _new_rx) => {
            // SCGI request not ready: loop for more rx data
            // TODO loop
            tx_scgi.send(handle_error(
                Error::new(ErrorKind::Other, "TODO partial requests aren't supported")
            )).await
        },
        (Some(Err(e)), _new_rx) =>
            // RX error: return error and abort
            Err(Error::new(ErrorKind::Other, format!("Error when waiting for request: {}", e))),
        (Some(Ok(request)), _) =>
            // Got SCGI request: pass to handler
            match handler.handle(request) {
                Ok(Some(r)) =>
                    // Response ready: send and exit
                    tx_scgi.send(r).await,
                Ok(None) =>
                    // Response not ready: loop for more rx data
                    Ok(()), // TODO loop
                Err(e) =>
                    // Handler error: respond with formatted error message
                    tx_scgi.send(handle_error(e)).await,
            },
    }
}

struct SampleHandler {


@@ 181,7 172,7 @@ impl SampleHandler {
    }

    /// This is where you'd put in your code accepting the request and returning a response.
    fn handle(&mut self, req: SCGIRequest) -> Result<AbortableItem<Vec<u8>>, Error> {
    fn handle(&mut self, req: SCGIRequest) -> Result<Option<Vec<u8>>, Error> {
        match req {
            // Accept the header and any POSTed payload in the body.
            SCGIRequest::Request(headers, body) => {


@@ 210,16 201,16 @@ impl SampleHandler {
                    match pair.1.parse() {
                        Ok(content_length) => {
                            if body.len() >= content_length {
                                // Looks like we've gotten everything. Return the response now.
                                // Looks like we've gotten everything. Send the response and exit.
                                // (The is the common case)
                                return Ok(AbortableItem::Stop(build_response(&headers, &body)));
                                return Ok(Some(build_response(&headers, &body)));
                            } else {
                                // Save current content, send empty/no-op response while we wait for
                                // the remainder.
                                self.headers = headers;
                                self.body_remaining = content_length - body.len();
                                self.body = body;
                                return Ok(AbortableItem::Continue(Vec::new()));
                                return Ok(None);
                            }
                        }
                        Err(e) => {


@@ 232,7 223,7 @@ impl SampleHandler {
                    }
                }
                // No Content-Length was found. Assume we've got everything and avoid more reads.
                Ok(AbortableItem::Stop(build_response(&headers, &body)))
                Ok(Some(build_response(&headers, &body)))
            }
            // Handle additional body fragments. This should only happen if we had returned Continue
            // above. For basic requests, this additional handling shouldn't be necessary. See above


@@ 247,15 238,11 @@ impl SampleHandler {
                self.body.put(more_body);

                if self.body_remaining <= 0 {
                    // We've gotten all the remaining data. Send the response, and tell upstream to
                    // not read from the socket again.
                    Ok(AbortableItem::Stop(build_response(
                        &self.headers,
                        &self.body,
                    )))
                    // We've gotten all the remaining data. Send the response and exit.
                    Ok(Some(build_response(&self.headers, &self.body)))
                } else {
                    // More data remains, continue waiting for it and return (another) empty noop.
                    Ok(AbortableItem::Continue(Vec::new()))
                    Ok(None)
                }
            }
        }

D src/abortable_stream.rs => src/abortable_stream.rs +0 -77
@@ 1,77 0,0 @@
#![deny(warnings, rust_2018_idioms)]

use tokio::prelude::*;

/// Type to be returned by the wrapped Stream. This tells the AbortableStream when it should avoid
/// making any additional calls to the underlying wrapped Stream.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum AbortableItem<T> {
    /// Continue reading after this item
    Continue(T),

    /// Stop reading after this item
    Stop(T),
}

/// Wraps an underlying stream, looking for a Stop value. When Stop is observed, it will return None
/// on the next poll.
pub struct AbortableStream<S, T, E> {
    stream: S,
    err_conv: Option<fn(E) -> Option<T>>,
    stop: bool,
}

impl<S, T, E> AbortableStream<S, T, E> {
    /// Creates a new instance, wrapping the provided stream and using the provided callback to
    /// convert errors before outputting them.
    pub fn with_err_conv(stream: S, err_conv: fn(E) -> Option<T>) -> AbortableStream<S, T, E> {
        AbortableStream {
            stream,
            err_conv: Some(err_conv),
            stop: false,
        }
    }

    /// Creates a new instance, wrapping the provided stream and passing through received errors
    /// directly.
    pub fn new(stream: S) -> AbortableStream<S, T, E> {
        AbortableStream {
            stream,
            err_conv: None,
            stop: false,
        }
    }
}

impl<S, T, E> Stream for AbortableStream<S, T, E>
where
    S: Stream<Item = AbortableItem<T>, Error = E>,
{
    type Item = T;
    type Error = E;

    fn poll(&mut self) -> Poll<Option<T>, Self::Error> {
        if self.stop {
            // Do not read from the wrapped stream, just exit.
            return Ok(Async::Ready(None));
        }
        match self.stream.poll() {
            // Interpret AbortableItem flag:
            Ok(Async::Ready(Some(AbortableItem::Continue(item)))) => Ok(Async::Ready(Some(item))),
            Ok(Async::Ready(Some(AbortableItem::Stop(item)))) => {
                self.stop = true;
                Ok(Async::Ready(Some(item)))
            }
            // Passthroughs:
            Ok(Async::Ready(None)) => Ok(Async::Ready(None)),
            Ok(Async::NotReady) => Ok(Async::NotReady),
            Err(err) => {
                // Use error converter, if provided.
                match self.err_conv {
                    Some(err_conv) => Ok(Async::Ready(err_conv(err))),
                    None => Err(err),
                }
            }
        }
    }
}

M src/lib.rs => src/lib.rs +0 -4
@@ 10,7 10,3 @@ pub mod server;

/// For an SCGI client (usually a web server): Builds SCGI requests and receives raw byte responses.
pub mod client;

/// Utility for a stream which will abort its NEXT call when told to do so by the thing it's
/// streaming against.
pub mod abortable_stream;