这个代码没有参考价值,大家不用看了
如果想看看实现的话参考这个吧:https://github.com/Addision/libevent_thread.git
只是windows 环境下, linux 需要自己写个cmake编译
服务器端代码:
#include "lib_net.h"
#include "lib_thread.h"
#include "lib_public.h"
#include<event.h>
#include<event2/util.h>
#define BACKLOG 10
#define MAX_EVENTS 500
char ip[24];
short port;
struct st_listenserv
{
int sockfd;
struct event *ev_listen;
struct event_base *base;
};
struct st_connserv
{
int clifd;
struct event_base *base;
struct event *ev_read;
struct event *ev_write;
char buf[1024];
};
void initsocket(struct st_listenserv *listenserv);
void accept_cb(int fd, short events, void *arg);
void read_cb(int fd, short events, void *arg);
void send_cb(int fd, short events, void *arg);
void start_thrd(int fd);
void thrd_readwri