IO
ev_io_init (ev_io *, callback, int fd, int events) ev_io_set (ev_io *, int fd, int events)
api
I/O watchers check whether a file descriptor is readable or writable in each iteration of the event loop, or, more precisely, when reading would not block the process and writing would at least be able to write some data.
NOTE :socket
水平触发(level-triggered,也被称为条件触发)LT: 只要知足条件,就触发一个事件(只要有数据没有被获取,内核就不断通知你)
边缘触发(edge-triggered)ET: 每当状态变化时,触发一个事件。
“举个读socket的例子,假定通过长时间的沉默后,如今来了100个字节,这时不管边缘触发和条件触发都会产生一个read ready notification通知应用程序可读。应用程序读了50个字节,而后从新调用api等待io事件。这时条件触发的api会由于还有50个字节可读,从而> 当即返回用户一个read ready notification。而边缘触发的api会由于可读这个状态没有发生变化而陷入长期等待。所以在使用边缘触发的api时,要注意每次都要读到socket返回EWOULDBLOCK为止,不然这个socket就算废了。而使用条件触发的api 时,若是应用程序不需> 要写就不要关注socket可写的事件,不然就会无限次的当即返回一个write ready notification。你们经常使用的select就是属于条件触发这一类,长期关注socket写事件会出现CPU 100%的毛病。oop