mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-12-02 11:57:43 +08:00
test aio timer
This commit is contained in:
parent
22264b9ade
commit
cd5f386e7c
@ -275,6 +275,36 @@ private:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class mytimer : public acl::aio_timer_callback {
|
||||||
|
public:
|
||||||
|
mytimer(long long delay) : id_(0), last_(time(NULL)), delay_(delay) {}
|
||||||
|
~mytimer(void) {}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// @override
|
||||||
|
void destroy(void) {
|
||||||
|
delete this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @override
|
||||||
|
void timer_callback(unsigned int id) {
|
||||||
|
time_t now = time(NULL);
|
||||||
|
delay_ += 1000000;
|
||||||
|
this->set_task(id_, delay_);
|
||||||
|
|
||||||
|
printf("timer id=%u, delay=%ld, next delay=%lld\r\n",
|
||||||
|
id, (long) (now - last_), delay_);
|
||||||
|
|
||||||
|
last_ = now;
|
||||||
|
id_ = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
unsigned int id_;
|
||||||
|
time_t last_;
|
||||||
|
long long delay_;
|
||||||
|
};
|
||||||
|
|
||||||
static void usage(const char* procname)
|
static void usage(const char* procname)
|
||||||
{
|
{
|
||||||
printf("usage: %s -h[help]\r\n"
|
printf("usage: %s -h[help]\r\n"
|
||||||
@ -325,6 +355,11 @@ int main(int argc, char* argv[])
|
|||||||
// 构建异步引擎类对象
|
// 构建异步引擎类对象
|
||||||
acl::aio_handle handle(use_kernel ? acl::ENGINE_KERNEL : acl::ENGINE_SELECT);
|
acl::aio_handle handle(use_kernel ? acl::ENGINE_KERNEL : acl::ENGINE_SELECT);
|
||||||
|
|
||||||
|
long long delay = 1000000;
|
||||||
|
mytimer* timer = new mytimer(delay);
|
||||||
|
timer->keep_timer(true);
|
||||||
|
handle.set_timer(timer, delay);
|
||||||
|
|
||||||
// 创建监听异步流
|
// 创建监听异步流
|
||||||
acl::aio_listen_stream* sstream = new acl::aio_listen_stream(&handle);
|
acl::aio_listen_stream* sstream = new acl::aio_listen_stream(&handle);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user