Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::net::{SocketAddr, TcpStream};
- use std::sync::mpsc;
- use std::thread;
- pub struct TelnetConfig {
- pub address: SocketAddr,
- }
- pub enum TelnetClientMessage {
- Outbound(String),
- }
- pub struct TelnetClient {
- config: TelnetConfig,
- telnet_socket: Option<TcpStream>,
- }
- impl TelnetClient {
- pub fn new(config: TelnetConfig) -> TelnetClient {
- let myself = TelnetClient {
- config,
- telnet_socket: None,
- };
- return myself;
- }
- pub fn start(&self) -> (mpsc::SyncSender<TelnetClientMessage>, thread::JoinHandle<()>, thread::JoinHandle<()>) {
- let (send_to_me, outbound_mailbox) = mpsc::sync_channel(0); // 0 byte buffer
- let mailbox_thread = thread::spawn(move || {self.mailbox_loop(outbound_mailbox); });
- let telnet_thread = thread::spawn(|| { self.telnet_loop(); });
- return (send_to_me, telnet_thread, mailbox_thread);
- }
- fn mailbox_loop(&mut self, mailbox: mpsc::Receiver<TelnetClientMessage>) {
- /* Outbound(x) => Send stuff to Telnet server */
- }
- fn telnet_loop(&mut self) { /* read from TcpStream and process it. */ }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement