Chinaunix首页 | 论坛 | 博客
  • 博客访问: 49604
  • 博文数量: 11
  • 博客积分: 85
  • 博客等级: 民兵
  • 技术积分: 163
  • 用 户 组: 普通用户
  • 注册时间: 2012-08-08 09:59
文章分类

全部博文(11)

文章存档

2013年(8)

2012年(3)

我的朋友

分类: C/C++

2013-04-10 16:54:15


点击(此处)折叠或打开

  1. class IOEvent
  2. {
  3. public:
  4.     void operator()(ev::io &w, int revents)
  5.     {
  6.         if (revents & ev::READ)
  7.             ReadEvent(w.fd);
  8.         if (revents & ev::WRITE)
  9.             WriteEvent(w.fd);
  10.     }

  11. protected:
  12.     IOEvent(int fd, struct ev_loop *lp)
  13.     {
  14.         _io.set(this);
  15.         _io.set(lp);
  16.         _io.start(fd, ev::NONE);
  17.     }
  18.     virtual ~IOEvent()
  19.     {
  20.         _io.stop();
  21.         close(_io.fd);
  22.     }
  23.     void SetEvents(int events)
  24.     {
  25.         _io.set(events);
  26.     }

  27. private:
  28.     ev::io _io;

  29.     virtual void ReadEvent(int fd) = 0;
  30.     virtual void WriteEvent(int fd) = 0;
  31. };

  32. class UDPEvent : private IOEvent
  33. {
  34. public:
  35.     UDPEvent(int fd, struct ev_loop *lp) : IOEvent(fd, lp)
  36.     {
  37.         SetEvents(ev::READ);
  38.     }

  39. private:
  40.     virtual void ReadEvent(int fd)
  41.     {
  42.     }
  43.     virtual void WriteEvent(int fd)
  44.     {
  45.     }
  46. }

阅读(2849) | 评论(0) | 转发(0) |
0

上一篇:strtok实现

下一篇:MySQL Connector/C++的使用

给主人留下些什么吧!~~