linux下进行操作
makefile
test:test.cpp
g++ $^ -o $@ -levent
./$@
clean:
rm -rf test
rm -rf *.o
测试代码
#include <iostream>
#include <event2/event.h>
#include <event2/thread.h>
#include<event2/listener.h>
#include <event2/bufferevent.h>
#include <errno.h>
#include <string>
#include <string.h>
#include <cstdio>
#ifndef _WIN32
#include <signal.h>
#else
#endif
using namespace std;
static string recvstr = "";
static int recvCount = 0;
static int sendCount = 0;
//错误,超时(连接断开会进入)
void event_cb(bufferevent* be,short events, void* arg)
{
cout << "[E]" << flush;
//读取超时事件发生后,数据停止读取
if (events & BEV_EVENT_TIMEOUT && events & BEV_EVENT_READING)
{
//读取缓冲中的数据
char data[1024] = { 0 };
//读取