1 module hunt.net.NetUtil;
2 
3 import hunt.net.EventLoopPool;
4 import hunt.net.NetClient;
5 import hunt.net.NetServer;
6 import hunt.net.NetClientImpl;
7 import hunt.net.NetClientOptions;
8 import hunt.net.NetServerImpl;
9 import hunt.net.NetServerOptions;
10 
11 import hunt.event.EventLoop;
12 import hunt.util.pool;
13 import hunt.logging;
14 
15 import std.concurrency : initOnce;
16 
17 
18 /**
19  * 
20  */
21 struct NetUtil {
22 
23     static EventLoop eventLoop() {
24         __gshared EventLoop inst;
25         return initOnce!inst(buildEventLoop());
26     }
27 
28     static EventLoop buildEventLoop() {
29         return EventLoopObjectFactory.buildEventLoop();
30         // EventLoop el = new EventLoop();
31         // version(HUNT_IO_DEBUG) warningf("Waiting for the eventloop[%d] got ready...", el.getId());
32         
33         // el.runAsync(-1);
34         // import core.thread;
35         // import core.time;
36         
37         // while(!el.isReady()) {
38         //     version(HUNT_IO_DEBUG_MORE) warning("Waiting for the eventloop got ready...");
39         // }
40         // version(HUNT_IO_DEBUG) warningf("eventloop[%d] is ready", el.getId());
41         // return el;
42     }
43 
44     static NetServer createNetServer(ThreadMode threadModel = ThreadMode.Single)() {
45         return new NetServerImpl!(threadModel)();
46     }
47 
48     static NetServer createNetServer(ThreadMode threadModel = ThreadMode.Single)(NetServerOptions options) {
49         return new NetServerImpl!(threadModel)(options);
50     }
51 
52     static NetClient createNetClient() {
53         return new NetClientImpl(eventLoopPool());
54     }
55 
56     static NetClient createNetClient(NetClientOptions options) {
57         return new NetClientImpl(eventLoopPool(), options);
58     }
59 }
60