#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <signal.h>
#ifdef _WIN32
#include <winsock2.h>
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "event.lib")
#pragma comment(lib, "event_extra.lib")
#pragma comment(lib, "event_core.lib")
#else
#include <netinet/in.h>
#include <pthread.h>
# ifdef _XOPEN_SOURCE_EXTENDED
# include <arpa/inet.h>
# endif
#include <sys/socket.h>
#define GetCurrentThreadId() pthread_self()
#endif
#include <event2/bufferevent.h>
#include <event2/buffer.h>
#include <event2/listener.h>
#include <event2/util.h>
#include <event2/event.h>
#include <event2/thread.h>
static const char MESSAGE[] = "Hello, World!\n";
static const int PORT = 9638;
static struct event_base * createEventBase();
static void conn_writecb(struct bufferevent *, void *);
static void conn_readcb(struct bufferevent *, void *);
static void conn_eventcb(struct bufferevent *, short, void *);
static void timer_callback(evutil_socket_t, short, void *);
static void connect_server(struct event_base* base);
int mainC(int argc, char **argv)
{
struct event_base *base;
struct event* timer = NULL;
#ifdef WIN32
libevent实现IOCP客户端
最新推荐文章于 2024-06-20 17:08:50 发布
该博客展示了如何使用libevent库在Windows环境下实现一个基于IO完成端口(IOCP)的客户端。主要涉及libevent的事件基(event_base)、套接字连接(bufferevent)、读写回调函数的配置,以及添加定时器保持模型运行。
摘要由CSDN通过智能技术生成