class Coolio::IOWatcher

Public Class Methods

Coolio::IOWatcher.initialize(IO, events = 'r') → Coolio::IOWatcher click to toggle source

Create a new Coolio::IOWatcher for the given IO object and add it to the given Coolio::Loop

static VALUE Coolio_IOWatcher_initialize(int argc, VALUE *argv, VALUE self)
{
  VALUE io, flags;
  char *flags_str;
  int events;
  struct Coolio_Watcher *watcher_data;

  rb_scan_args(argc, argv, "11", &io, &flags);

  if(flags != Qnil)
    flags_str = RSTRING_PTR(rb_String(flags));
  else
    flags_str = "r";

  if(!strcmp(flags_str, "r"))
    events = EV_READ;
  else if(!strcmp(flags_str, "w"))
    events = EV_WRITE;
  else if(!strcmp(flags_str, "rw"))
    events = EV_READ | EV_WRITE;
  else
    rb_raise(rb_eArgError, "invalid event type: '%s' (must be 'r', 'w', or 'rw')", flags_str);

  Data_Get_Struct(self, struct Coolio_Watcher, watcher_data);
  io = rb_convert_type(io, T_FILE, "IO", "to_io");

  watcher_data->dispatch_callback = Coolio_IOWatcher_dispatch_callback;
#ifdef HAVE_RB_IO_DESCRIPTOR
  ev_io_init(&watcher_data->event_types.ev_io, Coolio_IOWatcher_libev_callback, rb_io_descriptor(io), events);
#else
#if defined(HAVE_RB_IO_T)
  rb_io_t *fptr;
#else
  OpenFile *fptr;
#endif
  GetOpenFile(io, fptr);
  ev_io_init(&watcher_data->event_types.ev_io, Coolio_IOWatcher_libev_callback, FPTR_TO_FD(fptr), events);
#endif
  watcher_data->event_types.ev_io.data = (void *)self;

  return Qnil;
}

Public Instance Methods

Coolio::IOWatcher.attach(loop) → Coolio::IOWatcher click to toggle source

Attach the IO watcher to the given Coolio::Loop. If the watcher is already attached to a loop, detach it from the old one and attach it to the new one.

static VALUE Coolio_IOWatcher_attach(VALUE self, VALUE loop)
{
  Watcher_Attach(io, Coolio_IOWatcher_detach, self, loop);

  return self;  
}
Coolio::IOWatcher.detach → Coolio::IOWatcher click to toggle source

Detach the IO watcher from its current Coolio::Loop.

static VALUE Coolio_IOWatcher_detach(VALUE self)
{
  Watcher_Detach(io, self);

  return self;
}
Coolio::IOWatcher.disable → Coolio::IOWatcher click to toggle source

Temporarily disable an IO watcher which is attached to a loop.

This is useful if you wish to toggle event monitoring on and off.

static VALUE Coolio_IOWatcher_disable(VALUE self)
{
  Watcher_Disable(io, self);

  return self;
}
Coolio::IOWatcher.enable → Coolio::IOWatcher click to toggle source

Re-enable an IO watcher which has been temporarily disabled. See the disable method for a more thorough explanation.

static VALUE Coolio_IOWatcher_enable(VALUE self)
{
  Watcher_Enable(io, self);

  return self;  
}
Coolio::IOWatcher#on_readable → nil click to toggle source

Called whenever the IO object associated with the IOWatcher is readable

static VALUE Coolio_IOWatcher_on_readable(VALUE self)
{
  return Qnil;
}
Coolio::IOWatcher#on_writable → nil click to toggle source

Called whenever the IO object associated with the IOWatcher is writable

static VALUE Coolio_IOWatcher_on_writable(VALUE self)
{
  return Qnil;
}