Mercurial > lbo > hg > syslog
view src/dispatch.rs @ 24:ed9eb9cfeb83 draft
Add some notes and fix mod statements
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sun, 04 Dec 2016 16:32:49 +0100 |
parents | d680d7f1bec8 |
children |
line wrap: on
line source
//! This module contains the central event loop that receives and dispatches log messages. //! use std::io::Result; use config::Config; use dgram_stream; use futures::Stream; use tokio_core::reactor::Core; use tokio_uds::UnixDatagram; pub fn setup_and_run(cfg: Config) -> Result<()> { #[allow(non_snake_case)] let mut LOOP = try!(Core::new()); let handle = LOOP.handle(); let log_socket = try!(UnixDatagram::bind(cfg.general.bind_path, &handle)); // TODO: If we're listening to local messages as well as remote ones, build a custom future or // use Select. let log_incoming_stream = dgram_stream::new_unix_dgram_stream(cfg.general.max_msg_len, log_socket); // NOTE: Maybe a dedicated Future for this is simpler than for_each. let finished = log_incoming_stream.for_each(|msg_buf| { let msg = String::from_utf8(msg_buf).unwrap_or("<UTF8 decoding error>".to_string()); println!("{}", msg); Ok(()) }); LOOP.run(finished) }