@@ -18,94 +18,33 @@ void event_loop_ev::run()
1818 ev_run (loop_, 0 );
1919}
2020
21- void event_loop_ev::async_write (socket_identifier_t & watcher, const action& cb)
21+ void event_loop_ev::async_write (socket_identifier_t & watcher, action& & cb)
2222{
23- auto &handlers = watcher->write_handlers ;
24- handlers.push (cb);
25-
26- if (watcher->write_handlers .size () == 1 ) {
27- ev_io *w = &watcher->write_watcher ;
28- ev_io_start (loop_, w);
29- }
23+ watcher->start_writing_with (std::move (cb));
3024}
3125
32- void event_loop_ev::async_read (socket_identifier_t & watcher, const action& cb)
26+ void event_loop_ev::async_read (socket_identifier_t & watcher, action& & cb)
3327{
34- auto &handlers = watcher->read_handlers ;
35- handlers.push (cb);
36-
37- if (watcher->read_handlers .size () == 1 ) {
38- ev_io *w = &watcher->read_watcher ;
39- ev_io_start (loop_, w);
40- }
28+ watcher->start_reading_with (std::move (cb));
4129}
4230
43- void event_loop_ev::async_timeout (double time, const action& cb )
31+ void event_loop_ev::async_timeout (double time, action& & cb )
4432{
4533 timer_watcher *w = new timer_watcher (time, cb);
4634 ev_timer_start (loop_, &w->timer );
4735}
4836
49- void event_loop_ev::read_handler (EV_P_ ev_io* w, int revents)
50- {
51- if (revents & EV_ERROR)
52- return ;
53-
54- socket_queue* sq = reinterpret_cast <socket_queue*>(w->data );
55- auto &handlers = sq->read_handlers ;
56-
57- if (handlers.size ())
58- {
59- auto &action = handlers.front ();
60- action ();
61- handlers.pop ();
62- }
63-
64- if (!handlers.size ())
65- ev_io_stop (loop, &sq->read_watcher );
66- }
67-
68- void event_loop_ev::write_handler (EV_P_ ev_io* w, int revents)
69- {
70- if (revents & EV_ERROR)
71- return ;
72-
73- socket_queue* sq = reinterpret_cast <socket_queue*>(w->data );
74-
75- auto &handlers = sq->write_handlers ;
76-
77- if (handlers.size ())
78- {
79- auto &action = handlers.front ();
80- action ();
81- handlers.pop ();
82- }
83-
84- if (!handlers.size ())
85- ev_io_stop (loop, &sq->write_watcher );
86- }
87-
8837void event_loop_ev::timer_handler (EV_P_ ev_timer* w, int revents)
8938{
9039 timer_watcher *watcher = reinterpret_cast <timer_watcher*>(w);
9140 watcher->timeout_cb ();
9241 delete watcher;
9342}
9443
95- void event_loop_ev::stop (ev_io& io)
96- {
97- ev_clear_pending (loop_, &io);
98- ev_io_stop (loop_, &io);
99- }
100-
101- void event_loop_ev::start (ev_io& io)
102- {
103- ev_io_start (loop_, &io);
104- }
10544
10645event_loop_ev::socket_identifier_t event_loop_ev::watch (int fd)
10746{
108- return std::make_shared<event_loop_ev::socket_queue>(* this , fd);
47+ return std::make_shared<socket_watcher>(loop_ , fd);
10948}
11049
11150void event_loop_ev::unwatch (socket_identifier_t & id)
0 commit comments