tcp connection listener
This commit is contained in:
parent
8244e4ebf7
commit
72e2b31629
58
examples/tls/main.rs
Normal file
58
examples/tls/main.rs
Normal file
@ -0,0 +1,58 @@
|
||||
use std::net::TcpListener;
|
||||
|
||||
fn main() {
|
||||
let mut args = std::env::args();
|
||||
|
||||
let _bin = args.next();
|
||||
let entrypoint = args.next();
|
||||
|
||||
match entrypoint {
|
||||
Some(s) => match s.as_str() {
|
||||
"connection_listener" => connection_listener_entrypoint(),
|
||||
|
||||
_ => unimplemented!(),
|
||||
},
|
||||
None => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn connection_listener_entrypoint() {
|
||||
// imports
|
||||
use std::os::unix::io::{FromRawFd, RawFd};
|
||||
|
||||
// argument parsing
|
||||
let mut args = std::env::args();
|
||||
|
||||
let _bin = args.next();
|
||||
let _entrypoint = args.next();
|
||||
|
||||
let tcp_listener = args.next();
|
||||
let tcp_listener: RawFd = tcp_listener
|
||||
.expect("tcp listener required")
|
||||
.parse()
|
||||
.expect("tcp listener should be a file descriptor");
|
||||
let tcp_listener = unsafe { TcpListener::from_raw_fd(tcp_listener) };
|
||||
|
||||
// actual function body
|
||||
fn connection_listener(tcp_listener: TcpListener) -> i32 {
|
||||
println!("connection_listener entered");
|
||||
|
||||
// handle incoming connections
|
||||
for stream in tcp_listener.incoming() {
|
||||
let _stream = match stream {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
println!("connection listener: error: {}", e);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
println!("received a new connection");
|
||||
}
|
||||
|
||||
exitcode::OK
|
||||
}
|
||||
|
||||
// run function
|
||||
std::process::exit(connection_listener(tcp_listener));
|
||||
}
|
35
examples/tls/spec.json
Normal file
35
examples/tls/spec.json
Normal file
@ -0,0 +1,35 @@
|
||||
{
|
||||
"entrypoints": {
|
||||
"connection_listener": {
|
||||
"args": [
|
||||
"BinaryName",
|
||||
"Entrypoint",
|
||||
{
|
||||
"TcpListener": {
|
||||
"addr": "0.0.0.0:8443"
|
||||
}
|
||||
}
|
||||
],
|
||||
"environment": [
|
||||
{
|
||||
"Filesystem": {
|
||||
"host_path": "/lib/x86_64-linux-gnu/libgcc_s.so.1",
|
||||
"environment_path": "/lib/libgcc_s.so.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Filesystem": {
|
||||
"host_path": "/lib/x86_64-linux-gnu/libc.so.6",
|
||||
"environment_path": "/lib/libc.so.6"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Filesystem": {
|
||||
"host_path": "/lib64/ld-linux-x86-64.so.2",
|
||||
"environment_path": "/lib64/ld-linux-x86-64.so.2"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user