#connection-pool #ssl #tcp #connection-manager #client-connection

net-utils

Network utility library which provides client connection pool for TCP/SSL connctions

5 releases

Uses old Rust 2015

0.0.5 Jan 1, 2018
0.0.4 Dec 3, 2017
0.0.3 Apr 3, 2017
0.0.2 Jan 12, 2016
0.0.1 Dec 24, 2015

#14 in #connection-manager

MIT/Apache

40KB
919 lines

net-utils

Build Status

Provides networking utility including TCP/SSL connection and connection manager.

Here is an example of using connection pool.

Define the below dependency in Cargo.toml

[dependencies.net-utils]
git = "https://github.com/rohitjoshi/net-utils.git"

Here is your main.rs

extern crate "net-utils" as utils;
use std::default::Default;
use std::sync::{ Arc, Mutex };


use utils::net::config;
use utils::net::poolmgr;
fn main() {
    let mut cfg : config::Config = Default::default();
    //set port to 80
    cfg.port= Some(80);
    //set host to
    cfg.server = Some("google.com".to_string());
    let mut pool = poolmgr::ConnectionPool::new(2, 20, true, &cfg);
    //get the connection
    let mut conn = pool.aquire().unwrap();
    conn.writer.write_str("GET google.com\r\n").unwrap();
    conn.writer.flush().unwrap();
    let r = conn.reader.read_line();
    println!("Received {}", r);
    pool.release(conn);
}

Here is above example used in multi-threded environment

extern crate "net-utils" as utils;
use std::default::Default;
use std::sync::{ Arc, Mutex };


use utils::net::config;
use utils::net::poolmgr;

fn main() {
    let mut cfg : config::Config = Default::default();
    //set port to 80
    cfg.port= Some(80);
    //set host to
    cfg.server = Some("google.com".to_string());
    let mut pool = poolmgr::ConnectionPool::new(2, 20, true, &cfg);
    let pool = Arc::new(Mutex::new(pool));
    for _ in range(0u, 2) {
        let pool = pool.clone();
        spawn(move || {
            let mut conn = pool.lock().aquire().unwrap();
            conn.writer.write_str("GET google.com\r\n").unwrap();
            conn.writer.flush().unwrap();
            let r = conn.reader.read_line();
            println!("Received {}", r);
            pool.lock().release(conn);
       });
    }
}

To enable SSL connectivity, compile using --feature ssl e.g. For executing SSL test cases, run cargo test --features ssl

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~2.2–3.5MB
~73K SLoC