<commit_before>use flowgger::config::Config;

pub mod tcp_input;
#[cfg(feature = "coroutines")]
pub mod tcpco_input;

pub use super::Input;

const DEFAULT_FRAMING: &'static str = "line";
const DEFAULT_LISTEN: &'static str = "0.0.0.0:6514";
const DEFAULT_THREADS: usize = 1;
const DEFAULT_TIMEOUT: u64 = 3600;

#[derive(Clone)]
pub struct TcpConfig {
    framing: String,
    threads: usize
}

#[cfg(feature = "coroutines")]
fn get_default_threads(config: &Config) -> usize {
    config.lookup("input.tcp_threads").map_or(DEFAULT_THREADS, |x| x.as_integer().
        expect("input.tcp_threads must be an unsigned integer") as usize)
}

#[cfg(not(feature = "coroutines"))]
fn get_default_threads(_config: &Config) -> usize {
    1
}

pub fn config_parse(config: &Config) -> (TcpConfig, String, u64) {
    let listen = config.lookup("input.listen").map_or(DEFAULT_LISTEN, |x|x.as_str().
        expect("input.listen must be an ip:port string")).to_owned();
    let threads = get_default_threads(&config);
    let timeout = config.lookup("input.timeout").map_or(DEFAULT_TIMEOUT, |x| x.as_integer().
        expect("input.timeout must be an integer") as u64);
    let framing = if config.lookup("input.framed").map_or(false, |x| x.as_bool().
        expect("input.framed must be a boolean")) {
        "syslen"
    } else {
        DEFAULT_FRAMING
    };
    let framing = config.lookup("input.framing").map_or(framing, |x| x.as_str().
        expect(r#"input.framing must be a string set to "line", "nul" or "syslen""#)).to_owned();
    let tcp_config = TcpConfig {
        framing: framing,
        threads: threads
    };
    (tcp_config, listen, timeout)
}
<commit_msg>Don't define tcp/DEFAULT_THREADS when coroutines are disabled<commit_after>use flowgger::config::Config;

pub mod tcp_input;
#[cfg(feature = "coroutines")]
pub mod tcpco_input;

pub use super::Input;

const DEFAULT_FRAMING: &'static str = "line";
const DEFAULT_LISTEN: &'static str = "0.0.0.0:514";
#[cfg(feature = "coroutines")]
const DEFAULT_THREADS: usize = 1;
const DEFAULT_TIMEOUT: u64 = 3600;

#[derive(Clone)]
pub struct TcpConfig {
    framing: String,
    threads: usize
}

#[cfg(feature = "coroutines")]
fn get_default_threads(config: &Config) -> usize {
    config.lookup("input.tcp_threads").map_or(DEFAULT_THREADS, |x| x.as_integer().
        expect("input.tcp_threads must be an unsigned integer") as usize)
}

#[cfg(not(feature = "coroutines"))]
fn get_default_threads(_config: &Config) -> usize {
    1
}

pub fn config_parse(config: &Config) -> (TcpConfig, String, u64) {
    let listen = config.lookup("input.listen").map_or(DEFAULT_LISTEN, |x|x.as_str().
        expect("input.listen must be an ip:port string")).to_owned();
    let threads = get_default_threads(&config);
    let timeout = config.lookup("input.timeout").map_or(DEFAULT_TIMEOUT, |x| x.as_integer().
        expect("input.timeout must be an integer") as u64);
    let framing = if config.lookup("input.framed").map_or(false, |x| x.as_bool().
        expect("input.framed must be a boolean")) {
        "syslen"
    } else {
        DEFAULT_FRAMING
    };
    let framing = config.lookup("input.framing").map_or(framing, |x| x.as_str().
        expect(r#"input.framing must be a string set to "line", "nul" or "syslen""#)).to_owned();
    let tcp_config = TcpConfig {
        framing: framing,
        threads: threads
    };
    (tcp_config, listen, timeout)
}

{'fraction_non_alphanumeric': 0.15055653192735793, 'fraction_numerical': 0.011423550087873463, 'mean_word_length': 3.970887918486172, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7365475', 'n_tokens_mistral': 1176, 'n_tokens_neox': 1175, 'n_words': 278}