M Cargo.lock => Cargo.lock +29 -0
@@ 133,6 133,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
+name = "bitflags"
+version = "1.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
+
+[[package]]
name = "blocking"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ 217,6 223,16 @@ dependencies = [
]
[[package]]
+name = "ctrlc"
+version = "3.1.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b57a92e9749e10f25a171adcebfafe72991d45e7ec2dcb853e8f83d9dafaeb08"
+dependencies = [
+ "nix",
+ "winapi",
+]
+
+[[package]]
name = "env_logger"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ 450,6 466,18 @@ dependencies = [
]
[[package]]
+name = "nix"
+version = "0.18.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "83450fe6a6142ddd95fb064b746083fc4ef1705fe81f64a64e1d4b39f54a1055"
+dependencies = [
+ "bitflags",
+ "cc",
+ "cfg-if 0.1.10",
+ "libc",
+]
+
+[[package]]
name = "num-integer"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ 587,6 615,7 @@ version = "0.1.0"
dependencies = [
"async-std",
"chrono",
+ "ctrlc",
"futures",
"log",
"pretty_env_logger",
M Cargo.toml => Cargo.toml +1 -0
@@ 9,6 9,7 @@ license = "BSD-3-Clause"
async-std = "1"
chrono = "0.4"
+ctrlc = "3"
futures = "0.3"
log = "0.4"
pretty_env_logger = "0.4"
M src/bin/server.rs => src/bin/server.rs +14 -9
@@ 30,9 30,9 @@ enum Event {
Command {
msg: String,
},
- Broadcast {
- msg: String,
- },
+ //Broadcast {
+ // msg: String,
+ //},
}
/// This empty type enforces that no messages are sent down the shutdown channel.
@@ 122,11 122,11 @@ impl Server {
},
};
match event {
- Event::Broadcast { msg } => {
- for (_id, peer) in peers.iter_mut() {
- peer.send(msg.clone()).await?;
- }
- }
+ //Event::Broadcast { msg } => {
+ // for (_id, peer) in peers.iter_mut() {
+ // peer.send(msg.clone()).await?;
+ // }
+ //}
Event::Command { msg: _ } => {
// TODO - REDIS
}
@@ 135,7 135,7 @@ impl Server {
Entry::Occupied(..) => (),
Entry::Vacant(entry) => {
time_log!("New client {}: {}", id, stream.peer_addr()?);
-
+
// Send a welcome message.
// TODO can/should this be a separate type of Event, sent from connection_loop?
let welcome = format!("Hello!\nLocal time is: {}\n", now!());
@@ 213,6 213,11 @@ impl Default for Server {
pub fn main() -> Result<()> {
init_logging(2);
+ ctrlc::set_handler(|| {
+ time_log!("Server process recieved Ctrl-C, shutting down.",);
+ std::process::exit(0);
+ })?;
+
let server = Server::default();
let fut = server.accept_loop();