test.cpp
#include <iostream>
#include <event2/event.h>
#include <event2/thread.h>
#include<event2/listener.h>
#include <event2/bufferevent.h>
#include <errno.h>
#include <string.h>
#ifndef _WIN32
#include <signal.h>
#else
#endif
using namespace std;
//错误,超时(连接断开会进入)
void event_cb(bufferevent* be,short events, void* arg)
{
cout << "[E]" << flush;
//读取超时事件发生后,数据停止读取
if (events & BEV_EVENT_TIMEOUT && events & BEV_EVENT_READING)
{
cout << "BEV_EVENT_READING BEV_EVENT_TIMEOUT" << endl;
//bufferevent_enable(be, EV_READ);
bufferevent_free(be);
}
else if (events & BEV_EVENT_ERROR)
{
bufferevent_free(be);
}
else
{
cout << "OTHERS" << endl;
}
}
void write_cb(bufferevent* be, void* arg)
{
cout << "[W]" << flush;
}
void read_cb(bufferevent* be, void* arg)
{
cout