error: ‘evutil_socket_t’ has not been declared
thread.h:
#ifndef THREAD_H
#define THREAD_H
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <event2/event.h>
#include <event2/event_struct.h>
#include <event2/event_compat.h>
//线程类
class Thread
{
public:
Thread();
void start();//线程运行
//获取线程集合
struct event_base *getBase();
protected:
static void* worker(void*); //线程的工作函数
static void pipeRead(evutil_socket_t, short, void*);
void run(); //线程的逻辑处理函数
private:
struct event_base *m_base; //事件集合
pthread_t m_threadId; //线程ID
int m_pipeReadFd; //管道的读端
int m_pipeWriteFd; //管道的写端
struct event m_pipeEvent; //管道事件
};
#endif // THREAD_H
tcpserver.h:
#ifndef TCPSERVER_H
#define TCPSERVER_H
#include <thread.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <event2/listener.h>
#include <event2/bufferevent.h>
#include "tcpsocket.h"
class TcpSocket;
//Tcp服务的基类
class TcpServer
{
friend class TcpSocket;
public:
TcpServer(int threadNum = 8);
int listen(int port, const char *ip = NULL);
//服务器开始运行
void start();
protected:
//监听回调函数,有客户端连接的时候会调用这个函数
static void listenCb(struct evconnlistener *, evutil_socket_t, struct sockaddr *, int socklen, void *);
//监听处理函数
void listenEvent(evutil_socket_t fd, struct sockaddr_in *);
//--------------------虚函数 去具体处理客户端的逻辑--------------------
//客户端连接事件
virtual void connectEvent(TcpSocket *){}
//客户端可读
virtual void readEvent(TcpSocket *){}
//可写事件
virtual void writeEvent(TcpSocket *){}
//关闭事件
virtual void closeEvent(TcpSocket *, short ){}
private:
int m_threadNum; //线程个数
Thread *m_threadPool; //线程池
struct event_base *m_base;
struct evconnlistener *m_listener; //监听客户端的连接
int m_nextThread; //记录下一个线程的下标
};
#endif // TCPSERVER_H
/mnt/hgfs/BrainStorm/Server/thread.h:27: error: ‘evutil_socket_t’ has not been declared
static void pipeRead(evutil_socket_t, short, void*);
^~
/mnt/hgfs/BrainStorm/Server/thread.h:37: error: field ‘m_pipeEvent’ has incomplete type ‘event’
struct event m_pipeEvent; //管道事件
^~
/mnt/hgfs/BrainStorm/Server/tcpserver.h:31: error: ‘evutil_socket_t’ has not been declared
static void listenCb(struct evconnlistener *, evutil_socket_t, struct sockaddr *, int socklen, void *);
^~
/mnt/hgfs/BrainStorm/Server/tcpserver.h:34: error: ‘evutil_socket_t’ has not been declared
void listenEvent(evutil_socket_t fd, struct sockaddr_in *);
^~