From 7c1eb5cb0a86fd8198681d7ec53db092876de0cd Mon Sep 17 00:00:00 2001 From: Nora Widdecke Date: Thu, 4 Nov 2021 15:44:29 +0100 Subject: ipc: Update to tokio 1.0. - In assuan: - tokio::io::AsyncRead::poll_read now uses a ReadBuf buffer instead of a &mu [u8], so use that and write to the Client's buffer only if a read was successful. - Poll::Ready does not report n_read any more, so there cannot be a conflict between the reported and actual number of bytes read, remove that case. - Fixes #780. --- Cargo.lock | 298 ++++++++++----------------------------- ipc/Cargo.toml | 5 +- ipc/examples/assuan-client.rs | 2 +- ipc/examples/gpg-agent-client.rs | 2 +- ipc/src/assuan/mod.rs | 36 ++--- ipc/src/gnupg.rs | 4 +- ipc/src/lib.rs | 12 +- 7 files changed, 101 insertions(+), 258 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c6ff0088..c99ec6a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "addr2line" version = "0.16.0" @@ -70,7 +72,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -79,7 +81,7 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -119,7 +121,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi", "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -303,12 +305,6 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" -[[package]] -name = "bytes" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" - [[package]] name = "bytes" version = "1.1.0" @@ -422,7 +418,7 @@ dependencies = [ "num-traits", "time", "wasm-bindgen", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -501,7 +497,7 @@ checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59" dependencies = [ "atty", "lazy_static", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -799,7 +795,7 @@ checksum = "03d86534ed367a67548dc68113a0f5db55432fdfbb6e6f9d77704397d95d5780" dependencies = [ "libc", "redox_users", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -810,7 +806,7 @@ checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" dependencies = [ "libc", "redox_users", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -989,7 +985,7 @@ dependencies = [ "cfg-if 1.0.0", "libc", "redox_syscall", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1048,25 +1044,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" dependencies = [ "libc", - "winapi 0.3.9", -] - -[[package]] -name = "fuchsia-zircon" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" -dependencies = [ - "bitflags", - "fuchsia-zircon-sys", + "winapi", ] -[[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" - [[package]] name = "funty" version = "1.1.0" @@ -1160,7 +1140,7 @@ dependencies = [ "futures-sink", "futures-task", "memchr", - "pin-project-lite 0.2.7", + "pin-project-lite", "pin-utils", "proc-macro-hack", "proc-macro-nested", @@ -1177,7 +1157,7 @@ dependencies = [ "libc", "log", "rustversion", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1310,7 +1290,7 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fd819562fcebdac5afc5c113c3ec36f902840b70fd4fc458799c8ce4607ae55" dependencies = [ - "bytes 1.1.0", + "bytes", "fnv", "futures-core", "futures-sink", @@ -1318,8 +1298,8 @@ dependencies = [ "http", "indexmap", "slab", - "tokio 1.12.0", - "tokio-util 0.6.8", + "tokio", + "tokio-util", "tracing", ] @@ -1369,7 +1349,7 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1323096b05d41827dadeaee54c9981958c0f94e670bc94ed80037d1a7b8b186b" dependencies = [ - "bytes 1.1.0", + "bytes", "fnv", "itoa", ] @@ -1380,9 +1360,9 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ff4f84919677303da5f147645dbea6b1881f368d03ac84e1dc09031ebd7b2c6" dependencies = [ - "bytes 1.1.0", + "bytes", "http", - "pin-project-lite 0.2.7", + "pin-project-lite", ] [[package]] @@ -1409,7 +1389,7 @@ version = "0.14.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b91bb1f221b6ea1f1e4371216b70f40748774c2fb5971b450c07773fb92d26b" dependencies = [ - "bytes 1.1.0", + "bytes", "futures-channel", "futures-core", "futures-util", @@ -1419,9 +1399,9 @@ dependencies = [ "httparse", "httpdate", "itoa", - "pin-project-lite 0.2.7", + "pin-project-lite", "socket2 0.4.2", - "tokio 1.12.0", + "tokio", "tower-service", "tracing", "want", @@ -1433,10 +1413,10 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" dependencies = [ - "bytes 1.1.0", + "bytes", "hyper", "native-tls", - "tokio 1.12.0", + "tokio", "tokio-native-tls", ] @@ -1498,15 +1478,6 @@ dependencies = [ "cfg-if 1.0.0", ] -[[package]] -name = "iovec" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -dependencies = [ - "libc", -] - [[package]] name = "itertools" version = "0.8.2" @@ -1549,16 +1520,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - [[package]] name = "lalrpop" version = "0.19.6" @@ -1619,7 +1580,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0cf036d15402bea3c5d4de17b3fce76b3e4a56ebc1f577be0e7a72f7c607cf0" dependencies = [ "cfg-if 1.0.0", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1730,25 +1691,6 @@ dependencies = [ "autocfg 1.0.1", ] -[[package]] -name = "mio" -version = "0.6.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" -dependencies = [ - "cfg-if 0.1.10", - "fuchsia-zircon", - "fuchsia-zircon-sys", - "iovec", - "kernel32-sys", - "libc", - "log", - "miow 0.2.2", - "net2", - "slab", - "winapi 0.2.8", -] - [[package]] name = "mio" version = "0.7.14" @@ -1757,32 +1699,9 @@ checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc" dependencies = [ "libc", "log", - "miow 0.3.7", + "miow", "ntapi", - "winapi 0.3.9", -] - -[[package]] -name = "mio-uds" -version = "0.6.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0" -dependencies = [ - "iovec", - "libc", - "mio 0.6.23", -] - -[[package]] -name = "miow" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" -dependencies = [ - "kernel32-sys", - "net2", - "winapi 0.2.8", - "ws2_32-sys", + "winapi", ] [[package]] @@ -1791,7 +1710,7 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1812,17 +1731,6 @@ dependencies = [ "tempfile", ] -[[package]] -name = "net2" -version = "0.2.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "winapi 0.3.9", -] - [[package]] name = "nettle" version = "7.0.2" @@ -1874,7 +1782,7 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2066,7 +1974,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2218,12 +2126,6 @@ dependencies = [ "libc", ] -[[package]] -name = "pin-project-lite" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" - [[package]] name = "pin-project-lite" version = "0.2.7" @@ -2531,7 +2433,7 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2544,7 +2446,7 @@ dependencies = [ "log", "num_cpus", "rayon", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2578,7 +2480,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffc936cf8a7ea60c58f030fd36a612a48f440610214dc54bc36431f9ea0c3efb" dependencies = [ "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2652,7 +2554,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" dependencies = [ "lazy_static", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -2718,7 +2620,7 @@ dependencies = [ "sequoia-ipc", "sequoia-net", "sequoia-openpgp", - "tokio 1.12.0", + "tokio", ] [[package]] @@ -2763,9 +2665,9 @@ dependencies = [ "socket2 0.3.19", "tempfile", "thiserror", - "tokio 0.2.25", - "tokio-util 0.3.1", - "winapi 0.3.9", + "tokio", + "tokio-util", + "winapi", ] [[package]] @@ -2785,7 +2687,7 @@ dependencies = [ "sequoia-openpgp", "tempfile", "thiserror", - "tokio 1.12.0", + "tokio", "url", "zbase32", ] @@ -2842,7 +2744,7 @@ dependencies = [ "twofish", "typenum", "win-crypto-ng", - "winapi 0.3.9", + "winapi", "x25519-dalek", "xxhash-rust", ] @@ -2879,7 +2781,7 @@ dependencies = [ "subplotlib", "tempfile", "term_size", - "tokio 1.12.0", + "tokio", ] [[package]] @@ -3027,6 +2929,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" +[[package]] +name = "signal-hook-registry" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" +dependencies = [ + "libc", +] + [[package]] name = "signature" version = "1.3.2" @@ -3083,7 +2994,7 @@ checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" dependencies = [ "cfg-if 1.0.0", "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -3093,7 +3004,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5dc90fe6c7be1a323296982db1836d1ea9e47b6839496dde9a541bc496df3516" dependencies = [ "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -3286,7 +3197,7 @@ dependencies = [ "rand 0.8.4", "redox_syscall", "remove_dir_all 0.5.3", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -3330,7 +3241,7 @@ checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" dependencies = [ "dirs-next", "rustversion", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -3340,7 +3251,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e4129646ca0ed8f45d09b929036bafad5377103edd06e50bf574b353d2b08d9" dependencies = [ "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -3389,7 +3300,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" dependencies = [ "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -3426,24 +3337,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" -[[package]] -name = "tokio" -version = "0.2.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6703a273949a90131b290be1fe7b039d0fc884aa1935860dfcbe056f28cd8092" -dependencies = [ - "bytes 0.5.6", - "iovec", - "lazy_static", - "libc", - "memchr", - "mio 0.6.23", - "mio-uds", - "pin-project-lite 0.1.12", - "slab", - "tokio-macros 0.2.6", -] - [[package]] name = "tokio" version = "1.12.0" @@ -3451,24 +3344,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2c2416fdedca8443ae44b4527de1ea633af61d8f7169ffa6e72c5b53d24efcc" dependencies = [ "autocfg 1.0.1", - "bytes 1.1.0", + "bytes", "libc", "memchr", - "mio 0.7.14", - "pin-project-lite 0.2.7", - "tokio-macros 1.5.0", - "winapi 0.3.9", -] - -[[package]] -name = "tokio-macros" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e44da00bfc73a25f814cd8d7e57a68a5c31b74b3152a0a1d1f590c97ed06265a" -dependencies = [ - "proc-macro2", - "quote", - "syn", + "mio", + "num_cpus", + "once_cell", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "tokio-macros", + "winapi", ] [[package]] @@ -3489,22 +3375,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" dependencies = [ "native-tls", - "tokio 1.12.0", -] - -[[package]] -name = "tokio-util" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" -dependencies = [ - "bytes 0.5.6", - "futures-core", - "futures-io", - "futures-sink", - "log", - "pin-project-lite 0.1.12", - "tokio 0.2.25", + "tokio", ] [[package]] @@ -3513,12 +3384,13 @@ version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d3725d3efa29485e87311c5b699de63cde14b00ed4d256b8318aa30ca452cd" dependencies = [ - "bytes 1.1.0", + "bytes", "futures-core", + "futures-io", "futures-sink", "log", - "pin-project-lite 0.2.7", - "tokio 1.12.0", + "pin-project-lite", + "tokio", ] [[package]] @@ -3534,7 +3406,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" dependencies = [ "cfg-if 1.0.0", - "pin-project-lite 0.2.7", + "pin-project-lite", "tracing-attributes", "tracing-core", ] @@ -3786,7 +3658,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" dependencies = [ "same-file", - "winapi 0.3.9", + "winapi", "winapi-util", ] @@ -3885,16 +3757,10 @@ dependencies = [ "cipher", "doc-comment", "rand_core 0.5.1", - "winapi 0.3.9", + "winapi", "zeroize", ] -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" - [[package]] name = "winapi" version = "0.3.9" @@ -3905,12 +3771,6 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -3923,7 +3783,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -3932,16 +3792,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "ws2_32-sys" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - [[package]] name = "wyz" version = "0.2.0" diff --git a/ipc/Cargo.toml b/ipc/Cargo.toml index 66d7f728..9752189b 100644 --- a/ipc/Cargo.toml +++ b/ipc/Cargo.toml @@ -34,8 +34,9 @@ memsec = { version = ">=0.5", default-features = false } rand = { version = "0.7" } tempfile = "3.1" thiserror = "1.0.2" -tokio = { version = "0.2.19", features = ["rt-core", "rt-util", "tcp", "uds", "io-util", "macros"] } -tokio-util = { version = "0.3", features = ["compat"] } +#tokio = { version = "0.2.19", features = ["rt-core", "rt-util", "tcp", "uds", "io-util", "macros"] } +tokio = { version = "1", features = ["full"] } +tokio-util = { version = "0.6", features = ["compat"] } socket2 = "0.3.16" dirs = "2.0" diff --git a/ipc/examples/assuan-client.rs b/ipc/examples/assuan-client.rs index f6d19235..aa7f3ed8 100644 --- a/ipc/examples/assuan-client.rs +++ b/ipc/examples/assuan-client.rs @@ -15,7 +15,7 @@ fn main() { .help("Commands to send to the server")) .get_matches(); - let mut rt = tokio::runtime::Runtime::new().unwrap(); + let rt = tokio::runtime::Runtime::new().unwrap(); rt.block_on(async { let mut c = Client::connect(matches.value_of("server").unwrap()).await.unwrap(); for command in matches.values_of("commands").unwrap() { diff --git a/ipc/examples/gpg-agent-client.rs b/ipc/examples/gpg-agent-client.rs index f993b8c2..8f2d7415 100644 --- a/ipc/examples/gpg-agent-client.rs +++ b/ipc/examples/gpg-agent-client.rs @@ -23,7 +23,7 @@ fn main() { Context::new().unwrap() }; - let mut rt = tokio::runtime::Runtime::new().unwrap(); + let rt = tokio::runtime::Runtime::new().unwrap(); rt.block_on(async { let mut agent = Agent::connect(&ctx).await.unwrap(); diff --git a/ipc/src/assuan/mod.rs b/ipc/src/assuan/mod.rs index 5a4d9f20..5d6fd3d7 100644 --- a/ipc/src/assuan/mod.rs +++ b/ipc/src/assuan/mod.rs @@ -299,32 +299,24 @@ impl Stream for Client { } // No more linebreaks in the buffer. We need to get more. - // First, grow the buffer. - let buffer_len = buffer.len(); - buffer.resize(buffer_len + MAX_LINE_LENGTH, 0); - - match reader.as_mut().poll_read(cx, &mut buffer[buffer_len..])? { - Poll::Ready(n_read) if n_read == 0 => { - // EOF. - buffer.resize(buffer_len, 0); - if ! buffer.is_empty() { - // Incomplete server response. - return Poll::Ready(Some(Err(Error::ConnectionClosed( - buffer.clone()).into()))); - + // First, get a new read buffer. + // Later, append the read data to the Client's buffer + + let mut vec = vec![0u8; MAX_LINE_LENGTH]; + let mut read_buf = tokio::io::ReadBuf::new(&mut vec); + + match reader.as_mut().poll_read(cx, &mut read_buf)? { + Poll::Ready(()) => { + if read_buf.filled().is_empty() { + // End of stream. + return Poll::Ready(None) + } else { + buffer.extend_from_slice(read_buf.filled()); + continue; } - - // End of stream. - return Poll::Ready(None); - }, - - Poll::Ready(n_read) => { - buffer.resize(buffer_len + n_read, 0); - continue; }, Poll::Pending => { - buffer.resize(buffer_len, 0); return Poll::Pending; }, } diff --git a/ipc/src/gnupg.rs b/ipc/src/gnupg.rs index dc3ed078..8fb2c490 100644 --- a/ipc/src/gnupg.rs +++ b/ipc/src/gnupg.rs @@ -785,7 +785,7 @@ impl<'a> crypto::Signer for KeyPair<'a> { | (DSA, PublicKey::DSA { .. }) | (EdDSA, PublicKey::EdDSA { .. }) | (ECDSA, PublicKey::ECDSA { .. }) => { - let mut rt = tokio::runtime::Runtime::new()?; + let rt = tokio::runtime::Runtime::new()?; rt.block_on(async move { let mut a = Agent::connect_to(&self.agent_socket).await?; @@ -816,7 +816,7 @@ impl<'a> crypto::Decryptor for KeyPair<'a> { (PublicKey::RSA { .. }, Ciphertext::RSA { .. }) | (PublicKey::ElGamal { .. }, Ciphertext::ElGamal { .. }) | (PublicKey::ECDH { .. }, Ciphertext::ECDH { .. }) => { - let mut rt = tokio::runtime::Runtime::new()?; + let rt = tokio::runtime::Runtime::new()?; rt.block_on(async move { let mut a = Agent::connect_to(&self.agent_socket).await?; diff --git a/ipc/src/lib.rs b/ipc/src/lib.rs index 734725bb..c64d536e 100644 --- a/ipc/src/lib.rs +++ b/ipc/src/lib.rs @@ -162,8 +162,8 @@ impl Descriptor { stream.set_nodelay(true)?; let (reader, writer) = stream.into_split(); - use tokio_util::compat::Tokio02AsyncReadCompatExt; - use tokio_util::compat::Tokio02AsyncWriteCompatExt; + use tokio_util::compat::TokioAsyncReadCompatExt; + use tokio_util::compat::TokioAsyncWriteCompatExt; let (reader, writer) = (reader.compat(), writer.compat_write()); let network = @@ -388,7 +388,7 @@ impl Server { let handler = (self.descriptor.factory)(self.descriptor.clone(), &local)?; let server = async move { - let mut socket = tokio::net::TcpListener::from_std(l).unwrap(); + let socket = tokio::net::TcpListener::from_std(l).unwrap(); loop { let (mut socket, _) = socket.accept().await?; @@ -401,8 +401,8 @@ impl Server { let (reader, writer) = socket.into_split(); - use tokio_util::compat::Tokio02AsyncReadCompatExt; - use tokio_util::compat::Tokio02AsyncWriteCompatExt; + use tokio_util::compat::TokioAsyncReadCompatExt; + use tokio_util::compat::TokioAsyncWriteCompatExt; let (reader, writer) = (reader.compat(), writer.compat_write()); let network = @@ -414,7 +414,7 @@ impl Server { } }; - local.block_on(&mut self.runtime, server) + local.block_on(&self.runtime, server) } } -- cgit v1.2.3