- 论坛徽章:
- 0
|
看别人的一段代码。。。
void conn_clock(const int fd, const short which, void *arg)
{
struct timeval t = {.tv_sec = 0, .tv_usec = 100};
static char initialized = 0x0;
if (initialized)
{
evtimer_del(&conn_event);
}
else
{
initialized = 0x1;
}
if (total_connections >= max_connections)
{
return;
}
evtimer_set(&conn_event, conn_clock, 0);
event_base_set(ev_base, &conn_event);
evtimer_add(&conn_event, &t);
// Create connection
int cfd = create_conn(inet_addr(TEST_SRV_ADDR), TEST_SRV_PORT);
if (cfd > 0)
{
// Add to pool
conn_pool[total_connections] = cfd;
total_connections ++;
}
}
为什么递归的时候,每次都要用evtimer_del删除conn_event ? |
|