1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use ndata::dataobject::*;
use std::net::TcpListener;
use std::sync::RwLock;
use state::Storage;
use std::sync::Once;

use ndata::heap::Heap;

pub fn execute(o: DataObject) -> DataObject {
let a0 = o.get_string("address");
let a1 = o.get_i64("port");
let ax = listen(a0, a1);
let mut o = DataObject::new();
o.put_i64("a", ax);
o
}

pub fn listen(address:String, port:i64) -> i64 {
START.call_once(|| {
  TCPHEAP.set(RwLock::new(Heap::new()));
  xxx();
});

let socket_address = address + ":" + &port.to_string();
let listener = TcpListener::bind(socket_address).unwrap();
let _ = listener.set_nonblocking(true).unwrap();
let data_ref = &mut TCPHEAP.get().write().unwrap().push(listener);

*data_ref as i64
}

static START: Once = Once::new();
pub static TCPHEAP:Storage<RwLock<Heap<TcpListener>>> = Storage::new();

fn xxx() {
}