參考
libev Document
MinGW 編譯libevent
用Libev作TCP server的問題
Libev on Windows
libev源碼解析——總覽
重寫 libev 的 EV_WIN32_HANDLE_TO_FD
libev學習之ev_run
Libev輕網絡庫 源碼淺析
libev源碼解讀
網絡庫libevent、libev、libuv對比
說明
libev對windows支持不好,當然也可能是對mingw支持不好,官方是支持windows的,libuv貌似對windows的支持更好,libuv封裝了libev,linux下用libev實現,Windows下用IOCP實現。
方法
mingw下編譯libev,打開msys,
make clean
./configure --prefix=$cur_path/mingw-static-530_32 CFLAGS=-static --enable-static LDFLAGS=-static --disable-shared
make
make install
qt引用,測試初始化會卡死,
INCLUDEPATH += libev/include
LIBS += ..\recorder-server\libev\lib\libev.a
現採用直接在工程中使用源文件的方式,添加文件,
ev.c
ev.h
ev_select.c
ev_win32.c
ev_vars.h
ev_wrap.h
在前4個文件文件頭部添加下面三個宏,
#define EV_STANDALONE /* keeps ev from requiring config.h */
#define EV_USE_SELECT 1
#define EV_SELECT_IS_WINSOCKET 1 /* configure libev for windows select */
修改代碼,這兩個assert註釋,
ev.c: line2134 assert (("libev: only socket fds supported in this configuration", ret == 0));
ev_select.c: line85 assert (("libev: fd >= FD_SETSIZE passed to fd_set-based select backend", fd < FD_SETSIZE));
建一個線程跑EV_RUN,
void *jsonrpc_cmd_thread_func(void * param)
{
struct jrpc_server *server = (struct jrpc_server *)param;
printf("%s line%d thread enter\n", __FUNCTION__, __LINE__);
EV_RUN(server->loop, 0);
printf("%s line%d thread exit\n", __FUNCTION__, __LINE__);
EV_BREAK(server->loop, EVBREAK_ALL);
return 0;
}
ret = pthread_create(&tid, NULL, jsonrpc_cmd_thread_func, server);
if(ret != 0)
{
printf("%s failed\n", __FUNCTION__);
return ret;
}
現在可以編譯過,我測試,客戶端連接上之後,發送數據,服務端返回數據,然後EV_RUN
就退出了。。。無法再處理數據,有在mingw下成功使用libev的,不吝賜教。。。