1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16

use libc::rlimit;
use libc::setrlimit;
use libc::RLIMIT_NOFILE;

/// Set system limits on number of "open files", two files are used
/// per TCP socket in Linux
pub fn increase_rlimit_nofile(limit: u64) -> i32 {
    let lim = rlimit {
        rlim_cur: limit,
        rlim_max: limit
    };
    unsafe {
        return setrlimit(RLIMIT_NOFILE, &lim);
    }
}