// Libevent_Timer_Test.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "winsock2.h"
#include "event.h"
#include "iostream"
using namespace std;
//时间间隔1秒钟
static timeval t1 = {1,0};
static timeval t2 = {1,0};
void timer1(int sock,short which,void *arg)
{
//cout<<"[timer1]"<<endl;
event *ev = (event *)arg;
//如果事件处于非等待状态中,需要让事件重新变为等待状态,以便进入下次循环
if(!evtimer_pending(ev,&t1))
{
evtimer_del(ev);
evtimer_add(ev,&t1);
}
//Sleep(10000);
}
void timer2(int sock,short which,void *arg)
{
cout<<"[timer2]"<<endl;
//Sleep(5000);
}
void timer3(int sock,short which,void *arg)
{
//cout<<"[timer3]"<<endl;
//Sleep(10000);
}
int _tmain(int argc, _TCHAR* argv[])
{
//初始化socket库
WSADATA wsa;
WSAStartup(MAKEWORD(2,2),
Libevent---定时器使用示例
最新推荐文章于 2025-08-04 21:44:20 发布
