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;
}
void write_cb(bufferevent* be, void* arg)
{
cout << "[W]" << flush;
}
void read_cb(bufferevent* be, void* arg)
{
cout << "[R]" << flush;
char data[1024] = { 0 };
//读取输入缓冲数据
int len = bufferevent_read(be, data, sizeof(data) - 1);
cout << "[" << data << "]" << endl;
if (len <= 0) return;
if (strstr(data, "quit") != NULL)
{
cout << "quit";
//退出并关闭socket BEV_OPT_CLOSE_ON_FREE
bufferevent_free(be);
}
//发送数据,写入到输出