From e2df352ce6dbdbe8ac8076837c8f5d2cbd69208f Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 17 Oct 2019 03:28:42 -0400 Subject: pull some more hardcoded values into constants --- src/async_stdin.rs | 8 +++++--- src/client.rs | 9 +++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/async_stdin.rs b/src/async_stdin.rs index 5cfea44..e3b0ead 100644 --- a/src/async_stdin.rs +++ b/src/async_stdin.rs @@ -1,5 +1,7 @@ struct EventedStdin; +const STDIN: i32 = 0; + impl std::io::Read for EventedStdin { fn read(&mut self, buf: &mut [u8]) -> std::io::Result { let stdin = std::io::stdin(); @@ -16,7 +18,7 @@ impl mio::Evented for EventedStdin { interest: mio::Ready, opts: mio::PollOpt, ) -> std::io::Result<()> { - let fd = 0 as std::os::unix::io::RawFd; + let fd = STDIN as std::os::unix::io::RawFd; let eventedfd = mio::unix::EventedFd(&fd); eventedfd.register(poll, token, interest, opts) } @@ -28,13 +30,13 @@ impl mio::Evented for EventedStdin { interest: mio::Ready, opts: mio::PollOpt, ) -> std::io::Result<()> { - let fd = 0 as std::os::unix::io::RawFd; + let fd = STDIN as std::os::unix::io::RawFd; let eventedfd = mio::unix::EventedFd(&fd); eventedfd.reregister(poll, token, interest, opts) } fn deregister(&self, poll: &mio::Poll) -> std::io::Result<()> { - let fd = 0 as std::os::unix::io::RawFd; + let fd = STDIN as std::os::unix::io::RawFd; let eventedfd = mio::unix::EventedFd(&fd); eventedfd.deregister(poll) } diff --git a/src/client.rs b/src/client.rs index d4e925b..26ed108 100644 --- a/src/client.rs +++ b/src/client.rs @@ -10,6 +10,7 @@ const RECONNECT_BACKOFF_MAX: std::time::Duration = std::time::Duration::from_secs(60); const OAUTH_LISTEN_ADDRESS: &str = "127.0.0.1:44141"; +const OAUTH_BROWSER_SUCCESS_MESSAGE: &str = "authenticated successfully! now close this page and return to your terminal."; enum ReadSocket< S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static, @@ -398,10 +399,10 @@ impl .map(|_| (msg, sock)) }) .and_then(|(msg, sock)| { - let response = r"HTTP/1.1 200 OK - -authenticated successfully! now close this page and return to your terminal. -"; + let response = format!( + "HTTP/1.1 200 OK\n\n{}", + OAUTH_BROWSER_SUCCESS_MESSAGE + ); tokio::io::write_all(sock, response) .context(crate::error::WriteSocket) .map(|_| msg) -- cgit v1.2.3-54-g00ecf