tokio: "Example: an echo server using proto" does not work for me.
It accepts connections, but does not send back any data to socket.
$ rustc --version
rustc 1.19.0-nightly (2d4ed8e0c 2017-05-03)
$ cat Cargo.toml
[package]
name = "tokiotest"
version = "0.1.0"
authors = ["Vitaly _Vi Shukela <vi0oss@gmail.com>"]
[dependencies]
bytes = "0.4"
futures = "0.1"
tokio-io = "0.1"
tokio-proto = "0.1"
tokio-service = "0.1"
tokio-core = "0.1"
$ cat src/main.rs
extern crate tokio_proto;
extern crate tokio_core;
extern crate tokio_io;
extern crate futures;
extern crate tokio_service;
extern crate bytes;
use std::io;
use futures::future;
use futures::{Future, BoxFuture};
use tokio_io::{AsyncRead, AsyncWrite};
use tokio_io::codec::{Framed, Encoder, Decoder};
use bytes::BytesMut;
use tokio_proto::TcpServer;
use tokio_proto::pipeline::ServerProto;
use tokio_service::Service;
struct LineCodec;
impl Encoder for LineCodec {
type Item = String;
type Error = io::Error;
fn encode(&mut self, out: Self::Item, buf: &mut BytesMut) -> io::Result<()> {
Ok(())
}
}
impl Decoder for LineCodec {
type Item = String;
type Error = io::Error;
fn decode(&mut self, buf: &mut BytesMut) -> io::Result<Option<Self::Item>> {
Ok(None)
}
}
struct LineProto;
impl<T: AsyncRead + AsyncWrite + 'static> ServerProto<T> for LineProto {
type Request = String;
type Response = String;
type Transport = Framed<T, LineCodec>;
type BindTransport = Result<Self::Transport, io::Error>;
fn bind_transport(&self, io: T) -> Self::BindTransport {
Ok(io.framed(LineCodec))
}
}
struct Echo;
impl Service for Echo {
type Request = String;
type Response = String;
type Error = io::Error;
type Future = BoxFuture<Self::Response, Self::Error>;
fn call(&self, req: Self::Request) -> Self::Future {
future::ok(req).boxed()
}
}
fn main() {
// Specify the localhost address
let addr = "0.0.0.0:12345".parse().unwrap();
// The builder requires a protocol and an address
let server = TcpServer::new(LineProto, addr);
// We provide a way to *instantiate* the service for each new
// connection; here, we just immediately return a new instance.
server.serve(|| Ok(Echo));
}
$ strace -f ./target/x86_64-unknown-linux-gnu/debug/tokiotest
execve("./target/x86_64-unknown-linux-gnu/debug/tokiotest", ["./target/x86_64-unknown-linux-gn"...], [/* 29 vars */]) = 0
brk(NULL) = 0x31b00e97000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x3a773ddb000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=328047, ...}) = 0
mmap(NULL, 328047, PROT_READ, MAP_PRIVATE, 3, 0) = 0x3a773d8a000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\320\16\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=14664, ...}) = 0
mmap(NULL, 2109712, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x3a7739b9000
mprotect(0x3a7739bc000, 2093056, PROT_NONE) = 0
mmap(0x3a773bbb000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x3a773bbb000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/librt.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P#\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=31784, ...}) = 0
mmap(NULL, 2128920, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x3a7737b1000
mprotect(0x3a7737b8000, 2093056, PROT_NONE) = 0
mmap(0x3a7739b7000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6000) = 0x3a7739b7000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\320n\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=137384, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x3a773d89000
mmap(NULL, 2213008, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x3a773594000
mprotect(0x3a7735ac000, 2093056, PROT_NONE) = 0
mmap(0x3a7737ab000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x17000) = 0x3a7737ab000
mmap(0x3a7737ad000, 13456, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x3a7737ad000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260*\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=90096, ...}) = 0
mmap(NULL, 2185952, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x3a77337e000
mprotect(0x3a773394000, 2093056, PROT_NONE) = 0
mmap(0x3a773593000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x15000) = 0x3a773593000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\34\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1738176, ...}) = 0
mmap(NULL, 3844640, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x3a772fd3000
mprotect(0x3a773174000, 2097152, PROT_NONE) = 0
mmap(0x3a773374000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1a1000) = 0x3a773374000
mmap(0x3a77337a000, 14880, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x3a77337a000
close(3) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x3a773d88000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x3a773d86000
arch_prctl(ARCH_SET_FS, 0x3a773d86840) = 0
mprotect(0x3a773374000, 16384, PROT_READ) = 0
mprotect(0x3a7737ab000, 4096, PROT_READ) = 0
mprotect(0x3a7739b7000, 4096, PROT_READ) = 0
mprotect(0x3a773bbb000, 4096, PROT_READ) = 0
mprotect(0x31b0002d000, 28672, PROT_READ) = 0
mprotect(0x3a773ddd000, 4096, PROT_READ) = 0
munmap(0x3a773d8a000, 328047) = 0
set_tid_address(0x3a773d86b10) = 5837
set_robust_list(0x3a773d86b20, 24) = 0
rt_sigaction(SIGRTMIN, {sa_handler=0x3a77359a9b0, sa_mask=[], sa_flags=SA_RESTORER|SA_SIGINFO, sa_restorer=0x3a7735a3890}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {sa_handler=0x3a77359aa40, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART|SA_SIGINFO, sa_restorer=0x3a7735a3890}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
readlink("/etc/malloc.conf", 0x3ffacf57300, 4096) = -1 ENOENT (No such file or directory)
brk(NULL) = 0x31b00e97000
mmap(NULL, 2097152, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x3a772dd3000
munmap(0x3a772dd3000, 2097152) = 0
mmap(NULL, 4190208, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x3a772bd4000
munmap(0x3a772bd4000, 180224) = 0
munmap(0x3a772e00000, 1912832) = 0
open("/sys/devices/system/cpu/online", O_RDONLY|O_CLOEXEC) = 3
read(3, "0-3\n", 8192) = 4
close(3) = 0
rt_sigaction(SIGPIPE, {sa_handler=SIG_IGN, sa_mask=[PIPE], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x3a7730080e0}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
mmap(NULL, 2097152, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x3a772a00000
open("/proc/self/maps", O_RDONLY|O_CLOEXEC) = 3
getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
fstat(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x3a773dda000
read(3, "31affd19000-31affe2e000 r-xp 000"..., 1024) = 1024
read(3, "0-3a773394000 r-xp 00000000 fd:1"..., 1024) = 1024
read(3, "librt-2.19.so\n3a7739b7000-3a7739"..., 1024) = 1024
read(3, " /lib/x86_"..., 1024) = 428
close(3) = 0
munmap(0x3a773dda000, 4096) = 0
sched_getaffinity(5837, 32, [0, 1, 2, 3]) = 8
mmap(0x3ffac759000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x3ffac759000
rt_sigaction(SIGSEGV, {sa_handler=0x31affdbc140, sa_mask=[], sa_flags=SA_RESTORER|SA_STACK|SA_SIGINFO, sa_restorer=0x3a7735a3890}, NULL, 8) = 0
rt_sigaction(SIGBUS, {sa_handler=0x31affdbc140, sa_mask=[], sa_flags=SA_RESTORER|SA_STACK|SA_SIGINFO, sa_restorer=0x3a7735a3890}, NULL, 8) = 0
sigaltstack(NULL, {ss_sp=NULL, ss_flags=SS_DISABLE, ss_size=0}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x3a773dd9000
sigaltstack({ss_sp=0x3a773dd9000, ss_flags=0, ss_size=8192}, NULL) = 0
futex(0x3a773bbc0c8, FUTEX_WAKE_PRIVATE, 2147483647) = 0
epoll_create1(EPOLL_CLOEXEC) = 3
pipe2([4, 5], O_NONBLOCK|O_CLOEXEC) = 0
epoll_ctl(3, EPOLL_CTL_ADD, 4, {EPOLLIN|EPOLLET, {u32=4294967295, u64=18446744073709551615}}) = 0
socket(AF_INET, SOCK_STREAM, IPPROTO_IP) = 6
ioctl(6, FIOCLEX) = 0
setsockopt(6, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(6, {sa_family=AF_INET, sin_port=htons(12345), sin_addr=inet_addr("0.0.0.0")}, 16) = 0
listen(6, 1024) = 0
ioctl(6, FIONBIO, [1]) = 0
epoll_ctl(3, EPOLL_CTL_ADD, 6, {EPOLLIN|EPOLLOUT|EPOLLRDHUP|EPOLLET, {u32=2, u64=2}}) = 0
epoll_wait(3, [], 1024, 0) = 0
epoll_wait(3, [], 1024, 0) = 0
epoll_wait(3, [{EPOLLIN, {u32=2, u64=2}}], 1024, -1) = 1
write(5, "\1", 1) = 1
epoll_wait(3, [{EPOLLIN, {u32=4294967295, u64=18446744073709551615}}], 1024, 0) = 1
read(4, "\1", 128) = 1
read(4, 0x3ffacf56588, 128) = -1 EAGAIN (Resource temporarily unavailable)
accept4(6, {sa_family=AF_INET, sin_port=htons(35182), sin_addr=inet_addr("127.0.0.1")}, [128->16], SOCK_CLOEXEC) = 7
ioctl(7, FIONBIO, [1]) = 0
epoll_ctl(3, EPOLL_CTL_ADD, 7, {EPOLLIN|EPOLLOUT|EPOLLRDHUP|EPOLLET, {u32=4, u64=4}}) = 0
accept4(6, 0x3ffacf55dd0, [128], SOCK_CLOEXEC) = -1 EAGAIN (Resource temporarily unavailable)
epoll_wait(3, [{EPOLLOUT, {u32=4, u64=4}}], 1024, 0) = 1
epoll_wait(3, [], 1024, 0) = 0
epoll_wait(3, [{EPOLLIN|EPOLLOUT, {u32=4, u64=4}}], 1024, -1) = 1
write(5, "\1", 1) = 1
epoll_wait(3, [{EPOLLIN, {u32=4294967295, u64=18446744073709551615}}], 1024, 0) = 1
read(4, "\1", 128) = 1
read(4, 0x3ffacf56588, 128) = -1 EAGAIN (Resource temporarily unavailable)
recvfrom(7, "dsfadsf\n", 8192, 0, NULL, NULL) = 8
recvfrom(7, 0x3a772a5a008, 8184, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)
epoll_wait(3, [], 1024, 0) = 0
epoll_wait(3, [{EPOLLIN|EPOLLOUT, {u32=4, u64=4}}], 1024, -1) = 1
write(5, "\1", 1) = 1
epoll_wait(3, [{EPOLLIN, {u32=4294967295, u64=18446744073709551615}}], 1024, 0) = 1
read(4, "\1", 128) = 1
read(4, 0x3ffacf56588, 128) = -1 EAGAIN (Resource temporarily unavailable)
recvfrom(7, "213213214324\n", 8184, 0, NULL, NULL) = 13
recvfrom(7, 0x3a772a5a015, 8171, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)
epoll_wait(3, [], 1024, 0) = 0
epoll_wait(3, [{EPOLLIN|EPOLLOUT|EPOLLRDHUP, {u32=4, u64=4}}], 1024, -1) = 1
write(5, "\1", 1) = 1
epoll_wait(3, [{EPOLLIN, {u32=4294967295, u64=18446744073709551615}}], 1024, 0) = 1
read(4, "\1", 128) = 1
read(4, 0x3ffacf56588, 128) = -1 EAGAIN (Resource temporarily unavailable)
recvfrom(7, "", 8171, 0, NULL, NULL) = 0
close(7) = 0
epoll_wait(3, [], 1024, 0) = 0
epoll_wait(3, [], 1024, 0) = 0
epoll_wait(3, ^Cstrace: Process 5837 detached
<detached ...>
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 18 (18 by maintainers)
Commits related to this issue
- Fill in LineCodec implementation in example https://github.com/tokio-rs/tokio/issues/7 — committed to vi/tokio-rs-website by vi 7 years ago
- Use a timer heap instead of a timer wheel In general it's easier to implement and should have more predictable performance semantics for applications in general. More serious timer usage can go throu... — committed to tokio-rs/tokio by alexcrichton 8 years ago
- Fill in LineCodec implementation in example https://github.com/tokio-rs/tokio/issues/7 — committed to rust-av/website by vi 7 years ago
The implementation of the encoder:
isn’t doing anything?