写两个简单的demo,对照一下各自的方法

#include <sys/types.h>

#include <event2/event-config.h>

#include <sys/stat.h>
#ifndef _WIN32
#include <sys/queue.h>
#include <unistd.h>
#include <sys/time.h>
#else
#include <winsock2.h>
#include <windows.h>
#endif
#include <signal.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <event.h>
#include <event2/event.h> int called = ; static void
signal_cb(evutil_socket_t fd, short event, void *arg)
{
struct event *signal = arg; printf("signal_cb: got signal %d\n", event_get_signal(signal)); if (called >= )
event_del(signal); called++;
} int
main(int argc, char **argv)
{
struct event signal_int;
struct event_base* base;
#ifdef _WIN32
WORD wVersionRequested;
WSADATA wsaData; wVersionRequested = MAKEWORD(, ); (void) WSAStartup(wVersionRequested, &wsaData);
#endif /* Initalize the event library */
// base = event_base_new();
//
// /* Initalize one event */
// signal_int = evsignal_new(base, SIGINT, signal_cb, event_self_cbarg());
event_init();
event_set(&signal_int, SIGINT, EV_SIGNAL, signal_cb, (void *)&signal_int);
event_add(&signal_int, NULL); event_dispatch();
//event_free(signal_int);
//event_base_free(base); return ();
}
#include <sys/types.h>

#include <event2/event-config.h>

#include <sys/stat.h>
#ifndef _WIN32
#include <sys/queue.h>
#include <unistd.h>
#include <sys/time.h>
#else
#include <winsock2.h>
#include <windows.h>
#endif
#include <signal.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h> #include <event2/event.h> int called = 0; static void
signal_cb(evutil_socket_t fd, short event, void *arg)
{
struct event *signal = arg; printf("signal_cb: got signal %d\n", event_get_signal(signal)); if (called >= 2)
event_del(signal); called++;
} int
main(int argc, char **argv)
{
struct event *signal_int;
struct event_base* base;
#ifdef _WIN32
WORD wVersionRequested;
WSADATA wsaData; wVersionRequested = MAKEWORD(2, 2); (void) WSAStartup(wVersionRequested, &wsaData);
#endif /* Initalize the event library */
base = event_base_new(); /* Initalize one event */
signal_int = evsignal_new(base, SIGINT, signal_cb, event_self_cbarg());    //evsignal_new内部调用了event_new
    event_add(signal_int, NULL); 
    event_base_dispatch(base);
    event_free(signal_int);
    event_base_free(base); return (0);
}

  

最新文章

  1. Java 引用分类:StrongReference、SoftReference、WeakReference、PhantomReference
  2. MyBank(自助银行)系统
  3. 求出数组前面k个元素或数组中元素大于一半的元素(快速排序与堆排序的灵活运用)
  4. LeetCode题解——Add Two Numbers
  5. Graph(2014辽宁ACM省赛)
  6. Linux下搭建Oracle11g RAC(5)----配置ASM磁盘
  7. xml代码
  8. hibernate在地图的方法之一协会
  9. 1572: [Usaco2009 Open]工作安排Job[贪心]
  10. 监控利器 sysdig - 每天5分钟玩转 Docker 容器技术(79)
  11. Aurora 论坛图片下载
  12. python scrapy框架爬虫遇到301
  13. docker镜像常用操作
  14. PDFBOX详解
  15. Oracle EBS FA 资产取值
  16. jsp button onclick
  17. 基于MSAA的QQ界面信息获取的实现
  18. APP消息推送机制的实现(PUSH)
  19. C++代码统计工具
  20. orcale_proceduie_function_两三栗

热门文章

  1. Wordpress 忘记密码怎么办?
  2. &lt;数据挖掘导论&gt;读书笔记7 Apriori算法
  3. Javascript替代eval方法
  4. Magento 2开发教程 - 创建新模块
  5. 阿里云配置HTTPS
  6. 提交代码至coding.net
  7. spring-boot之简单定时任务
  8. java 类与对象基础整理
  9. 【转载】RocketMQ与Kafka对比(18项差异)
  10. Linux From Scratch(从零开始构建Linux系统,简称LFS)(一)