int main(int argc, char* argv[])
{
    int fd = timerfd_create(CLOCK_MONOTONIC,TFD_NONBLOCK | TFD_CLOEXEC);

    ChannelPtr channel(new Channel(fd));
    channel->setChannel2Read();
    channel->setReadCallback(func);

    EventLoop loop;
    loop.updateChannel(channel);

    elp = &loop;

    struct itimerspec howlog;

    bzero(&howlog, sizeof(howlog));

    howlog.it_value.tv_sec = 5;

    timerfd_settime(fd,0,&howlog,NULL);

    cout << "begin" <<endl;

    loop.Start();

    close(fd);

    return 0;
}
Example #2
0
int main(int argc, char** argv)
{
    EventLoop loop;
    int fd = ::socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC,6);
    if (fd < 0)
    {
        LOG_INFO << "Fail to open test file";
        return -1;
    }
    dbdky::port::Channel chl(&loop, fd);
    chl.setWriteCallback(boost::bind(&defaultWriteEventCallback));
    chl.setCloseCallback(boost::bind(&defaultCloseEventCallback));
    //chl.setReadCallback(boost::bind(&defaultReadEventCallback)(_1));
   
    loop.updateChannel(&chl);

    loop.loop();
    
    return 0;    
}