ext/iodine/iodine_connection.c
/** Fires a connection object's event */
Fires a connection object's event
Fires a connection object ' s event
void iodine_connection_fire_event(VALUE connection,
                                  iodine_connection_event_type_e ev,
                                  VALUE msg) {
  if (!connection || connection == Qnil) {
    FIO_LOG_ERROR(
        "(iodine) nil connection handle used by an internal API call");
    return;
  }
  iodine_connection_data_s *data = iodine_connection_validate_data(connection);
  if (!data) {
    FIO_LOG_ERROR("(iodine) invalid connection handle used by an "
                  "internal API call: %p",
                  (void *)connection);
    return;
  }
  if (!data->info.handler || data->info.handler == Qnil) {
    FIO_LOG_DEBUG("(iodine) invalid connection handler, can't fire event %d",
                  (int)ev);
    return;
  }
  VALUE args[2] = {connection, msg};
  switch (ev) {
  case IODINE_CONNECTION_ON_OPEN:
    if (data->answers_on_open) {
      IodineCaller.call2(data->info.handler, on_open_id, 1, args);
    }
    break;
  case IODINE_CONNECTION_ON_MESSAGE:
    if (data->answers_on_message) {
      IodineCaller.call2(data->info.handler, on_message_id, 2, args);
    }
    break;
  case IODINE_CONNECTION_ON_DRAINED:
    if (data->answers_on_drained) {
      IodineCaller.call2(data->info.handler, on_drained_id, 1, args);
    }
    break;
  case IODINE_CONNECTION_ON_SHUTDOWN:
    if (data->answers_on_shutdown) {
      IodineCaller.call2(data->info.handler, on_shutdown_id, 1, args);
    }
    break;
  case IODINE_CONNECTION_PING:
    if (data->answers_ping) {
      IodineCaller.call2(data->info.handler, ping_id, 1, args);
    }
    break;
  case IODINE_CONNECTION_ON_CLOSE:
    if (data->answers_on_close) {
      IodineCaller.call2(data->info.handler, on_close_id, 1, args);
    }
    fio_lock(&data->lock);
    iodine_sub_clear_all(&data->subscriptions);
    data->info.handler = Qnil;
    data->info.env = Qnil;
    data->info.uuid = -1;
    data->info.arg = NULL;
    fio_unlock(&data->lock);
    IodineStore.remove(connection);
    break;
  default:
    break;
  }
}
void iodine_connection_fire_event ( VALUE connection , iodine_connection_event_type_e ev , VALUE msg ) { if ( ! connection || connection == Qnil ) { FIO_LOG_ERROR ( " " ) ; return ; } iodine_connection_data_s * data = iodine_connection_validate_data ( connection ) ; if ( ! data ) { FIO_LOG_ERROR ( " " " " , ( void * ) connection ) ; return ; } if ( ! data -> info . handler || data -> info . handler == Qnil ) { FIO_LOG_DEBUG ( " " , ( int ) ev ) ; return ; } VALUE args [ 2 ] = { connection , msg } ; switch ( ev ) { case IODINE_CONNECTION_ON_OPEN : if ( data -> answers_on_open ) { IodineCaller . call2 ( data -> info . handler , on_open_id , 1 , args ) ; } break ; case IODINE_CONNECTION_ON_MESSAGE : if ( data -> answers_on_message ) { IodineCaller . call2 ( data -> info . handler , on_message_id , 2 , args ) ; } break ; case IODINE_CONNECTION_ON_DRAINED : if ( data -> answers_on_drained ) { IodineCaller . call2 ( data -> info . handler , on_drained_id , 1 , args ) ; } break ; case IODINE_CONNECTION_ON_SHUTDOWN : if ( data -> answers_on_shutdown ) { IodineCaller . call2 ( data -> info . handler , on_shutdown_id , 1 , args ) ; } break ; case IODINE_CONNECTION_PING : if ( data -> answers_ping ) { IodineCaller . call2 ( data -> info . handler , ping_id , 1 , args ) ; } break ; case IODINE_CONNECTION_ON_CLOSE : if ( data -> answers_on_close ) { IodineCaller . call2 ( data -> info . handler , on_close_id , 1 , args ) ; } fio_lock ( & data -> lock ) ; iodine_sub_clear_all ( & data -> subscriptions ) ; data -> info . handler = Qnil ; data -> info . env = Qnil ; data -> info . uuid = -1 ; data -> info . arg = NULL ; fio_unlock ( & data -> lock ) ; IodineStore . remove ( connection ) ; break ; default : break ; } }
Fires a connection object's event
Fires a connection object ' s event