1 /* 2 * Hunt - A refined core library for D programming language. 3 * 4 * Copyright (C) 2018-2019 HuntLabs 5 * 6 * Website: https://www.huntlabs.net/ 7 * 8 * Licensed under the Apache-2.0 License. 9 * 10 */ 11 12 module hunt.event.timer.Kqueue; 13 14 import hunt.Exceptions; 15 16 // dfmt off 17 version (HAVE_KQUEUE) : 18 // dfmt on 19 20 import hunt.io.socket.Common; 21 import hunt.event.timer.Common; 22 import hunt.io.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(ChannelFlag.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 }