日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

linux下使用NetBeans调试libevent库

發(fā)布時間:2023/11/27 生活经验 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux下使用NetBeans调试libevent库 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1.安裝libevent

參考:http://blog.csdn.net/unix21/article/details/8679269

libevent安裝在usr/local/libevent下


2.安裝netBeans

http://www.netbeans.org


3.配置netBeans

1)打開項目的屬性選項,選擇包含目錄,把/usr//local/libevent/include目錄加進(jìn)來



2) 鏈接器,在【其他庫目錄】把libevent的lib目錄加上,在【庫】中把要鏈接的庫文件設(shè)為libevent/lib中的libevent.so即可。


3)運(yùn)行程序


4)調(diào)試程序

可以跳入到libevent的代碼下



5) 程序:

#include <cstdlib>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <event2/event.h>
#include <event2/event_struct.h>
#include <unistd.h>using namespace std;#define N 300#define BUFLEN 256struct timeval lasttime;struct ST_EventWithDescription
{struct event *p_event;int time_interval;char lable[BUFLEN];
};static void timeout_cb(evutil_socket_t fd, short event, void *arg)
{struct timeval newtime, difference;struct ST_EventWithDescription *pSTEvent = (ST_EventWithDescription*)arg;struct event *timeout = pSTEvent->p_event;double elapsed;evutil_gettimeofday(&newtime, NULL);evutil_timersub(&newtime, &lasttime, &difference);elapsed = difference.tv_sec + (difference.tv_usec / 1.0e6);printf("%s called at %d: %.3f seconds since my last work.\n",(char*)pSTEvent->lable,(int)newtime.tv_sec, elapsed);lasttime = newtime;struct timeval tv;evutil_timerclear(&tv);tv.tv_sec = pSTEvent->time_interval;event_add(timeout, &tv);
}void setParam(struct ST_EventWithDescription *stEventDescription,struct event *m_event,int time_interval,char* m_lable)
{stEventDescription->p_event = m_event;stEventDescription->time_interval = time_interval;memset(stEventDescription->lable,0,sizeof(stEventDescription->lable));memcpy(stEventDescription->lable,m_lable,strlen(m_lable)+1);
}void setTimeIntervalArr(int *arr,int n)
{int i;srand(time(NULL));for(i=0; i<n; ++i){*(arr+i) = rand()%n + 1;//*(arr+i) = i+1;}
}int main(int argc, char** argv) {struct event timeout[N];struct ST_EventWithDescription stEvent[N];int time_interval[N];int i=0;struct timeval tv;struct event_base *base;int flags = 0;setTimeIntervalArr(time_interval,N);base = event_base_new();evutil_timerclear(&tv);for(i=0; i<N; ++i){char buf[BUFLEN]= {0};sprintf(buf,"task%d",i+1);setParam(stEvent+i,timeout+i,time_interval[i],buf);event_assign(timeout+i, base, -1, flags, timeout_cb, (void*)(stEvent+i));event_add(timeout+i, &tv);}evutil_gettimeofday(&lasttime, NULL);event_base_dispatch(base);return 0;
}

4.說明

如果是C語言選對應(yīng)選項即可


原文參考:http://hi.baidu.com/492943457/item/ca73933c34698e27b3c0c528

總結(jié)

以上是生活随笔為你收集整理的linux下使用NetBeans调试libevent库的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。