1 /*
2  * Kiss - A refined core library for D programming language.
3  *
4  * Copyright (C) 2015-2018  Shanghai Putao Technology Co., Ltd
5  *
6  * Developer: HuntLabs.cn
7  *
8  * Licensed under the Apache-2.0 License.
9  *
10  */
11  
12 module kiss.event.timer.kqueue;
13 
14 import kiss.core;
15 
16 // dfmt off
17 version (Kqueue) : 
18 // dfmt on
19 
20 import kiss.event.core;
21 import kiss.event.timer.common;
22 import kiss.event.socket;
23 
24 import core.stdc.errno;
25 import core.sys.posix.sys.types; // for ssize_t, size_t
26 import core.sys.posix.netinet.tcp;
27 import core.sys.posix.netinet.in_;
28 import core.sys.posix.time;
29 import core.sys.posix.unistd;
30 
31 import std.exception;
32 import std.socket;
33 
34 /**
35 */
36 class AbstractTimer : TimerChannelBase
37 {
38     this(Selector loop)
39     {
40         super(loop);
41         setFlag(WatchFlag.Read, true);
42         _sock = new Socket(AddressFamily.UNIX, SocketType.STREAM);
43         this.handle = _sock.handle;
44         _readBuffer = new UintObject();
45     }
46 
47     ~this()
48     {
49         close();
50     }
51 
52 
53     bool readTimer(scope ReadCallBack read)
54     {
55         this.clearError();
56         this._readBuffer.data = 1;
57         if (read)
58             read(this._readBuffer);
59         return false;
60     }
61 
62     UintObject _readBuffer;
63     Socket _sock;
64 }