withoutboats / romio

asynchronous networking primitives

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Event is no longer triggered, asking for help

SiMaCuo opened this issue · comments

commented
  • rustc 1.35.0-nightly (cb2f34dc6 2019-03-22)
  • romio-0.3.0-alpha.3
    I am writing a proxy software, in the CopyInto poll interface, the data is read from the socket of the connection server, and then the received data is written to the socket connected to receiving end.
    From the log collected locally, after the time point of 16:16:15:3796373, the future seems to be asleep, until after 5 minutes, it is awakened by the receiving end rst message.
    From the data collected by the server-side tcpdump, the data is normally sent, but the client does not read the data in time, causing the socket to be full.
    What is the problem that causes the buffer to have data but the future is not awakened. Is there any problem with my code?
    The actual code logic starts at line 51: https://gist.github.com/SiMaCuo/f7317c8e279bcc7b2ff489434464b5ea
    repo: https://github.com/SiMaCuo/ss-local
    I am very grateful for any suggestions.
    Sorry, my english is poor.
    微信图片_20190403232139

微信图片_20190403234556

commented

You can use the implementation from futures-rs: https://github.com/rust-lang-nursery/futures-rs/blob/master/futures-util/src/io/copy_into.rs.

Would you please test it with futures-rs impl and tell us whether you code got stuck again?

commented

@kpp I am not too familiar with tokio and romio, rewriting the copy_into function in your link is for select! use together. select! requires FusedFuture to be implemented: https://github.com/SiMaCuo/ss-local/blob/c075cd53210641c17186b9a310548e477871f377/src/service.rs#L249
If I want to use the code directly in future-rs, how can I achieve a similar effect?

commented

@kpp I replaced the code I wrote with the original poll implementation in future-rs. On the 96, 97, and 110 lines, read_done, write_done is set to ensure that select! can exit in this case. Still stuck. https://gist.github.com/SiMaCuo/0eb519912a8e8469902514bc1e208ddb#file-copy_into-rs-L96
However, in the case of FusedFuture, this code has a bug. If poll_read, poll_write returns an error, try_ready returns directly, I can't set read_done, write_done.
Any suggestions?
TIM图片20190404090531

commented

Why did you copy the code? What stops you from importing futures-rs and using CopyInto? Have a look at example https://docs.rs/futures-preview/0.3.0-alpha.13/futures/prelude/trait.AsyncReadExt.html#method.copy_into

Take a look how it is used in romio: https://github.com/withoutboats/romio/blob/master/examples/shakespeare-client.rs

Also you can turn any Future into FusedFuture by calling https://docs.rs/futures-preview/0.3.0-alpha.13/futures/future/trait.FutureExt.html#method.fuse

commented

problem solved, it is my mistake,thanks for your help. @kpp