fix_getting_started/
fix_getting_started.rs1use std::{
2 env,
3 io::{stdin, Read},
4 process::exit,
5};
6
7use quickfix::*;
8
9#[derive(Default)]
10pub struct MyApplication;
11
12impl ApplicationCallback for MyApplication {
13 fn on_create(&self, _session: &SessionId) {
16 }
18}
19
20fn main() -> Result<(), QuickFixError> {
21 let args: Vec<_> = env::args().collect();
22 let Some(config_file) = args.get(1) else {
23 eprintln!("Bad program usage: {} <config_file>", args[0]);
24 exit(1);
25 };
26
27 println!(">> Creating resources");
28 let settings = SessionSettings::try_from_path(config_file)?;
29 let store_factory = FileMessageStoreFactory::try_new(&settings)?;
30 let log_factory = LogFactory::try_new(&StdLogger::Stdout)?;
31 let callbacks = MyApplication;
32 let app = Application::try_new(&callbacks)?;
33
34 let mut acceptor = Acceptor::try_new(
35 &settings,
36 &app,
37 &store_factory,
38 &log_factory,
39 FixSocketServerKind::SingleThreaded,
40 )?;
41
42 println!(">> connection handler START");
43 acceptor.start()?;
44
45 println!(">> App running, press 'q' to quit");
46 let mut stdin = stdin().lock();
47 let mut stdin_buf = [0];
48 loop {
49 let _ = stdin.read_exact(&mut stdin_buf);
50 if stdin_buf[0] == b'q' {
51 break;
52 }
53 }
54
55 println!(">> connection handler STOP");
56 acceptor.stop()?;
57
58 println!(">> All cleared. Bye !");
59 Ok(())
60}