}
struct event_watch *
-event_add_watch(int fd, int w, struct callback *cb)
+event_add_watch(struct file *file, enum event_watch_cond cond, struct callback *cb)
{
- return event_methods.add_watch(fd, w, cb);
+ return event_methods.add_watch(file, cond, cb);
}
void
struct event_timeout;
struct event_watch;
struct callback;
+struct file;
+
+enum event_watch_cond {
+ event_watch_cond_read=1,
+ event_watch_cond_write,
+ event_watch_cond_except,
+};
struct event_methods {
void (*main_loop_run)(void);
void (*main_loop_quit)(void);
- struct event_watch *(*add_watch)(int fd, int w, struct callback *cb);
+ struct event_watch *(*add_watch)(struct file *file, enum event_watch_cond cond, struct callback *cb);
void (*remove_watch)(struct event_watch *ev);
struct event_timeout *(*add_timeout)(int timeout, int multi, struct callback *cb);
void (*remove_timeout)(struct event_timeout *ev);
void (*remove_idle)(struct event_idle *ev);
};
+
/* prototypes */
void event_main_loop_run(void);
void event_main_loop_quit(void);
-struct event_watch *event_add_watch(int fd, int w, struct callback *cb);
+struct event_watch *event_add_watch(struct file *file, enum event_watch_cond cond, struct callback *cb);
void event_remove_watch(struct event_watch *ev);
struct event_timeout *event_add_timeout(int timeout, int multi, struct callback *cb);
void event_remove_timeout(struct event_timeout *ev);
}
static struct event_watch *
-event_glib_add_watch(int fd, int w, struct callback *cb)
+event_glib_add_watch(struct file *file, enum event_watch_cond cond, struct callback *cb)
{
struct event_watch *ret=g_new0(struct event_watch, 1);
+ int flags=0,fd=(int)file_get_os_handle(file);
ret->iochan = g_io_channel_unix_new(fd);
- ret->source = g_io_add_watch(ret->iochan, G_IO_IN | G_IO_ERR | G_IO_HUP, event_glib_call_watch, (gpointer)cb);
+ switch (cond) {
+ case event_watch_cond_read:
+ flags=G_IO_IN;
+ break;
+ case event_watch_cond_write:
+ flags=G_IO_OUT;
+ break;
+ case event_watch_cond_except:
+ flags=G_IO_ERR|G_IO_HUP;
+ break;
+ }
+ ret->source = g_io_add_watch(ret->iochan, cond, event_glib_call_watch, (gpointer)cb);
return ret;
}
#endif
}
+void *
+file_get_os_handle(struct file *file)
+{
+ return (void *)(file->fd);
+}
+
void
file_init(void)
{