当前位置: 首页 > news >正文

网购网站建设视频教程seo81

网购网站建设视频教程,seo81,在线做数据图的网站有哪些问题,家具类网站如何优化背景 libevent libevent – an event notification library 官方定义:libevent是一个事件通知的库。更详细的介绍参考官方的就够了,这里我摘抄一下,并做一些注释 The libevent API provides a mechanism to execute a callback function whe…

背景

libevent

libevent – an event notification library

官方定义:libevent是一个事件通知的库。更详细的介绍参考官方的就够了,这里我摘抄一下,并做一些注释

The libevent API provides a mechanism to execute a callback function when a specific event occurs on a file descriptor or after a timeout has been reached. Furthermore, libevent also support callbacks due to signals or regular timeouts.

libevent提供API来支持在文件描述符发生事件或者超时后调用回调函数的机制。

libevent is meant to replace the event loop found in event driven network servers. An application just needs to call event_dispatch() and then add or remove events dynamically without having to change the event loop.

libevent目的是在事件驱动的网络服务器中取代事件循环。应用只需要调用event_dispatch()然后动态添加或者删除事件,并不需要去修改事件循环。总结一下:libevent是为了取缔在应用中手写事件循环。

Currently, libevent supports dev/poll, kqueue(2), event ports, POSIX select(2), Windows select(), poll(2), and epoll(4). The internal event mechanism is completely independent of the exposed event API, and a simple update of libevent can provide new functionality without having to redesign the applications. As a result, Libevent allows for portable application development and provides the most scalable event notification mechanism available on an operating system. Libevent can also be used for multi-threaded applications, either by isolating each event_base so that only a single thread accesses it, or by locked access to a single shared event_base. Libevent should compile on Linux, *BSD, Mac OS X, Solaris, Windows, and more.

目前,libevent支持/dev/poll, kqueue, event ports, POSIX select, Windows select, poll, 和 epoll

Libevent additionally provides a sophisticated framework for buffered network IO, with support for sockets, filters, rate-limiting, SSL, zero-copy file transmission, and IOCP. Libevent includes support for several useful protocols, including DNS, HTTP, and a minimal RPC framework.

More information about event notification mechanisms for network servers can be found on Dan Kegel’s “The C10K problem” web page.

阅读libevent动机

  1. libevent被广泛应用,是一个成熟的、稳定的事件驱动库
  2. 阅读一下优秀的开源C代码,学习

libevent源码结构

整个源码包解压下来,根目录里面是一堆信息文件、源代码、CMakeLists文件、configure相关文件以及测试例子等文件夹。
其中:

  1. README.md是项目说明文件,编译安装可以参考。
  2. include文件夹是库对外提供的头文件,使用libevent库的时候需要包含。
  3. 其他文件

接着,我们看下编译构建文件夹,这里我们按照README中的方法,新建文件夹build作为构建目录。

build/
├── bin
├── CMakeCache.txt
├── CMakeFiles
├── cmake_install.cmake
├── compile_commands.json
├── CTestTestfile.cmake
├── DartConfiguration.tcl
├── include
├── lib
├── LibeventConfig.cmake
├── LibeventConfigVersion.cmake
├── libevent_core.pc
├── libevent_extra.pc
├── libevent_openssl.pc
├── libevent.pc
├── libevent_pthreads.pc
├── LibeventTargets-shared.cmake
├── LibeventTargets-static.cmake
├── Makefile
├── Testing
├── tmp
├── Uninstall.cmake
└── verify_tests.sh

其中:

  1. bin文件夹是一些测试例子程序
  2. CMakeFiles文件夹是一些中间cmake配置
  3. include文件夹是cmake生成的头文件,这里面定义了不同的系统以及配置,帮助libevent实现跨平台
  4. lib文件夹是编译生成的动态库和静态库
  5. 其他文件

libevent库的使用

编译完后,我们第一步肯定是要学习怎么在自己的项目中使用这个库。
在编译完后,libevent会产生下面几个动态库和静态库(build/lib):

# 编译选项 -levent
libevent-2.1.so.7.0.1
libevent.a
# 编译选项 -levent_core
libevent_core-2.1.so.7.0.1
libevent_core.a
# 编译选项 -levent_extra
libevent_extra-2.1.so.7.0.1
libevent_extra.a
# 编译选项 -levent_openssl -levent
libevent_openssl-2.1.so.7.0.1
libevent_openssl.a
# 编译选项 -levent_pthreads -levent
libevent_pthreads-2.1.so.7.0.1
libevent_pthreads.a

一个例子 test-libevent.c


#include<unistd.h>
#include<stdio.h>
#include"libevent-2.1.12-stable/include/event2/event.h"    // libevent库的头文件
#include"libevent-2.1.12-stable/include/event2/thread.h"void cmd_cb(int fd, short events, void *arg)
{char buf[1024];printf("in the cmd_cb\n");read(fd, buf, sizeof(buf));
}int main()
{evthread_use_pthreads();//使用默认的event_base配置struct event_base *base = event_base_new();struct event *cmd_ev = event_new(base, STDIN_FILENO,EV_READ | EV_PERSIST, cmd_cb, NULL);event_add(cmd_ev, NULL); //没有超时event_base_dispatch(base);return 0;
}

编译:

# 使用编译出来的动态库,需要通过-L指定编译时使用的库路径,同时需要使用rpath选项指定程序运行时使用的库路径(避免使用系统自带的库)
gcc  test-libevent.c -levent -levent_pthreads -levent_extra -L/build/lib/ -Wl,-rpath,build/lib
ldd a.out linux-vdso.so.1 (0x00007ffc0d558000)libevent-2.1.so.7 => build/lib/libevent-2.1.so.7 (0x00007f387b284000)libevent_pthreads-2.1.so.7 => build/lib/libevent_pthreads-2.1.so.7 (0x00007f387b27f000)libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f387b07f000)libevent_core-2.1.so.7 => /home/czw/workspace/czw/libevent-notes/notes/build/lib/libevent_core-2.1.so.7 (0x00007f387b040000)/lib64/ld-linux-x86-64.so.2 (0x00007f387b2f0000)
# 使用编译出来的静态库,直接把静态文件作为编译时的文件
gcc  test-libevent.c build/lib/libevent.a build/lib/libevent_pthreads.a
ldd a.out linux-vdso.so.1 (0x00007ffcadb80000)libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f817f4a2000)/lib64/ld-linux-x86-64.so.2 (0x00007f817f6c9000)

reference

  1. https://libevent.org/
http://www.hengruixuexiao.com/news/34748.html

相关文章:

  • vs2008 新建网站网站seo招聘
  • 动画制作流程南宁seo收费
  • php 网站目录结构去哪里推广软件效果好
  • wordpres做影视网站360优化大师旧版
  • 做外贸重新设计网站怎么理解搜索引擎优化
  • 精品课程网站建设意义百度seo关键词外包
  • 深圳网站建设三把火百度下载免费安装最新版
  • 郑州网站建设公司排行黄页推广平台有哪些
  • 免费建立永久网站口碑seo推广公司
  • 阿里云个人网站建设书网站友情链接是什么
  • 个人网站支付解决方案他达拉非片正确服用方法
  • 网站开发 协作平台seo服务商排名
  • wordpress批量目录seo站长工具查询
  • 网站建设源码苏州百度推广代理商
  • 淘宝客网站搜索怎么做谷歌浏览器下载安装
  • 创意网络武汉seo招聘
  • 申报城市维护建设税上哪个网站公众号怎么推广和引流
  • 做网站是什么课手机建网站软件
  • 网页设计音乐网站求个网站
  • 徐州做网站重庆百度seo
  • 企业网站建设哪家专业一个网站的seo优化有哪些
  • 西宁企业网站建设开发苹果cms永久免费全能建站程序
  • 网站备案登记表成人再就业技能培训班
  • 品牌网站建设seo推广官网
  • 多个织梦dedecms网站怎么做站群优化大师apk
  • 公司网站后台操作成都网站建设企业
  • 佛山网站建设原创大连最好的做网站的公司
  • 投资公司投资项目流程seo建站工具
  • 如皋网站设计百度公司官网招聘
  • 佛山建网站哪里好泰安seo推广