libevent 一 簡單使用

2021-07-09 20:44:43 字數 4492 閱讀 6353

tar -xvf  libevent-

2.0.22

-stable

.tar.gz;

cd cd libevent-

2.0.22

-stable

./configure --prefix=/mydir

make

make install

安裝完後,可以看到安裝後的額目錄結構如下:

└── hiredis.pc二.使用

2.1 定時器和訊號

test_event.c:

#include

#include

#include

void ontime(int fd, short

event, void* arg)

void onsigusr1(int sig, short

event, void* arg)

int main()

//增加定時器

timer = evtimer_new(base, ontime, &timer);

tv.tv_sec = 10;

tv.tv_usec = 0;

event_add(timer, &tv);

//增加訊號監聽

esig = evsignal_new(base, sigusr1, onsigusr1, null);

event_add(esig, null);

event_base_dispatch(base);

return

0;}

makefile

all:test_event.c

gcc -o test_event test_event.c -i/mydir/include -l/mydir/lib -levent

執行結果 , (中間向程序發了一次sigusr1訊號):

./test_event

ontime

called

!ontime

called

!recieve

sig10

ontime

called

!

2.2 socket

參考example: a low-level rot13 server with libevent

cgo使用libevent庫實現乙個定時器

go和c互相呼叫指標 git clone cd libevent mkdir build cd build cmake make main.cpp include event.h struct event ev struct timeval tv void time cb evutil socket...

linux下使用libevent開發遇到的齷齪問題

按照網上例子搞了個httpd的小demo linvo httpd.c 遇到一連串問題,努力google了半天,終於得解,記錄之 環境 linux 2.6.18 164.el5 libevent 1.4.13 首先用gcc編譯時候報了類似下面資訊的一堆錯 應該是找不到編譯後的libevent庫檔案所導...

libevent在windows下使用步驟詳解

libevent官網 windows 8下編譯 編譯環境 windows 8 vs2013 1 解壓libevent到d libevent libevent 2.0.21 stable 2 開啟microsoft visual studio 2010 命令列工具 3 修改以下三個檔案,新增巨集定義 ...