From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH xtermjs 2/3] update to mio 0.7
Date: Mon, 1 Feb 2021 08:55:17 +0100 [thread overview]
Message-ID: <20210201075518.21727-3-d.csapak@proxmox.com> (raw)
In-Reply-To: <20210201075518.21727-1-d.csapak@proxmox.com>
notable changes:
* all polls in mio are now edge triggered, so no need for PollOpt, etc.
* functionality of UnixReady is now in the mio::Event directly
(UnixReady::is_hup -> event.is_read_closed())
* TcpListener::from_std() is not a result anymore
* EventedFd -> SourceFd
* mio::net::TcpListener cannot accept_std anymore, so convert
everywhere to mio::net::TcpStream, drop set_read_timeout
(this warrants another patch)
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/main.rs | 48 ++++++++++++++++++++----------------------------
1 file changed, 20 insertions(+), 28 deletions(-)
diff --git a/src/main.rs b/src/main.rs
index 12e70bc..07fa1a8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,7 +2,6 @@ use std::cmp::min;
use std::collections::HashMap;
use std::ffi::{OsStr, OsString};
use std::io::{ErrorKind, Result, Write};
-use std::net::TcpStream;
use std::os::unix::io::{AsRawFd, FromRawFd};
use std::os::unix::process::CommandExt;
use std::process::Command;
@@ -10,9 +9,9 @@ use std::time::{Duration, Instant};
use clap::{App, AppSettings, Arg};
use curl::easy::Easy;
-use mio::net::TcpListener;
-use mio::unix::{EventedFd, UnixReady};
-use mio::{Events, Poll, PollOpt, Ready, Token};
+use mio::net::{TcpListener, TcpStream};
+use mio::{Events, Poll, Token, Interest};
+use mio::unix::SourceFd;
use proxmox::sys::error::io_err_other;
use proxmox::sys::linux::pty::{make_controlling_terminal, PTY};
@@ -98,7 +97,6 @@ fn read_ticket_line(
if buf.is_full() || now.elapsed() >= timeout {
io_bail!("authentication data is incomplete: {:?}", &buf[..]);
}
- stream.set_read_timeout(Some(Duration::new(1, 0)))?;
match buf.read_from(stream) {
Ok(n) => {
if n == 0 {
@@ -110,7 +108,6 @@ fn read_ticket_line(
}
}
- stream.set_read_timeout(None)?;
let newline_idx = &buf[..].iter().position(|&x| x == b'\n').unwrap();
let line = buf.remove_data(*newline_idx);
@@ -182,10 +179,10 @@ fn listen_and_accept(
std::net::TcpListener::bind((hostname, port as u16))?
};
let port = listener.local_addr()?.port();
- let listener = TcpListener::from_std(listener)?;
- let poll = Poll::new()?;
+ let mut listener = TcpListener::from_std(listener);
+ let mut poll = Poll::new()?;
- poll.register(&listener, Token(0), Ready::readable(), PollOpt::edge())?;
+ poll.registry().register(&mut listener, Token(0), Interest::READABLE)?;
let mut events = Events::with_capacity(1);
@@ -195,7 +192,7 @@ fn listen_and_accept(
poll.poll(&mut events, Some(timeout))?;
let elapsed = now.elapsed();
if !events.is_empty() {
- let (stream, client) = listener.accept_std()?;
+ let (stream, client) = listener.accept()?;
println!("client connection: {:?}", client);
return Ok((stream, port));
}
@@ -287,34 +284,30 @@ fn do_main() -> Result<()> {
return Err(io_format_err!("Invalid FD number"));
}
- let (mut stream, port) =
+ let (mut tcp_handle, port) =
listen_and_accept("localhost", port, use_port_as_fd, Duration::new(10, 0))
.map_err(|err| io_format_err!("failed waiting for client: {}", err))?;
- let (username, ticket) = read_ticket_line(&mut stream, &mut pty_buf, Duration::new(10, 0))
+ let (username, ticket) = read_ticket_line(&mut tcp_handle, &mut pty_buf, Duration::new(10, 0))
.map_err(|err| io_format_err!("failed reading ticket: {}", err))?;
let port = if use_port_as_fd { Some(port) } else { None };
authenticate(&username, &ticket, path, perm, authport, port)?;
- stream.write_all(b"OK").expect("error writing response");
+ tcp_handle.write_all(b"OK").expect("error writing response");
- let mut tcp_handle = mio::net::TcpStream::from_stream(stream)?;
-
- let poll = Poll::new()?;
+ let mut poll = Poll::new()?;
let mut events = Events::with_capacity(128);
let mut pty = run_pty(cmd, cmdparams)?;
- poll.register(
- &tcp_handle,
+ poll.registry().register(
+ &mut tcp_handle,
TCP,
- Ready::readable() | Ready::writable() | UnixReady::hup(),
- PollOpt::edge(),
+ Interest::READABLE.add(Interest::WRITABLE)
)?;
- poll.register(
- &EventedFd(&pty.as_raw_fd()),
+ poll.registry().register(
+ &mut SourceFd(&pty.as_raw_fd()),
PTY,
- Ready::readable() | Ready::writable() | UnixReady::hup(),
- PollOpt::edge(),
+ Interest::READABLE.add(Interest::WRITABLE)
)?;
let mut tcp_writable = true;
@@ -332,10 +325,9 @@ fn do_main() -> Result<()> {
}
for event in &events {
- let readiness = event.readiness();
- let writable = readiness.is_writable();
- let readable = readiness.is_readable();
- if UnixReady::from(readiness).is_hup() {
+ let writable = event.is_writable();
+ let readable = event.is_readable();
+ if event.is_read_closed() {
finished = true;
}
match event.token() {
--
2.20.1
next prev parent reply other threads:[~2021-02-01 7:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-01 7:55 [pbs-devel] [PATCH xtermjs 0/3] update to mio 0.7 (part of tokio 1.0) Dominik Csapak
2021-02-01 7:55 ` [pbs-devel] [PATCH xtermjs 1/3] Cargo.toml: update mio to 0.7 and proxmox to 0.10 Dominik Csapak
2021-02-01 7:55 ` Dominik Csapak [this message]
2021-02-01 7:55 ` [pbs-devel] [PATCH xtermjs 3/3] termproxy: rewrite read_ticket_line Dominik Csapak
2021-02-02 12:10 ` [pbs-devel] applied-series: [PATCH xtermjs 0/3] update to mio 0.7 (part of tokio 1.0) Fabian Grünbichler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210201075518.21727-3-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox