Example #1
0
uint64_t
rwmsg_toyfd_del(rwmsg_toytask_t *toy, uint64_t id)
{
  rwsched_instance_ptr_t instance;
  rwmsg_toytask_t *toytask = toy;
  CFSocketContext cf_context = { 0, NULL, NULL, NULL, NULL };
  rwsched_CFSocketRef cfsocket;
  struct rwmsg_toyfd_s *toyfd;
  rwsched_CFRunLoopSourceRef cfsource = NULL;

  // Validate input parameters
  RW_CF_TYPE_VALIDATE(toytask, rwtoytask_tasklet_ptr_t);

  // Get the rwsched instance from the toytask
  instance = toytask->toysched->rwsched_instance;
  RW_CF_TYPE_VALIDATE(instance, rwsched_instance_ptr_t);

  // Lookup the cfsocket corresponding to id
  RW_ASSERT(id < toytask->rwsched_tasklet_info->cfsocket_array->len);
  cfsocket = g_array_index(toytask->rwsched_tasklet_info->cfsocket_array, rwsched_CFSocketRef, id);
  RW_ASSERT(cfsocket->index == id);
  rwsched_tasklet_CFSocketGetContext(toytask->rwsched_tasklet_info, cfsocket, &cf_context);

  // Free the cfsocket
  rwsched_tasklet_CFSocketInvalidate(toytask->rwsched_tasklet_info, cfsocket);
  rwsched_tasklet_CFSocketRelease(toytask->rwsched_tasklet_info, cfsocket);

  toyfd = cf_context.info;
  // Free the cfsource
  if ((cfsource = toyfd->read_context.source.cfsource)) {
    RW_CF_TYPE_VALIDATE(cfsource, rwsched_CFRunLoopSourceRef);
    //rwsched_tasklet_CFRunLoopRemoveSource(toytask->rwsched_tasklet_info, cfsource, instance->main_cfrunloop_mode);
    rwsched_tasklet_CFSocketReleaseRunLoopSource(toytask->rwsched_tasklet_info, cfsource);
    toyfd->read_context.source.cfsource = NULL;
  } else if ((cfsource = toyfd->write_context.source.cfsource)) {
    RW_CF_TYPE_VALIDATE(cfsource, rwsched_CFRunLoopSourceRef);
    //rwsched_tasklet_CFRunLoopRemoveSource(toytask->rwsched_tasklet_info, cfsource, instance->main_cfrunloop_mode);
    rwsched_tasklet_CFSocketReleaseRunLoopSource(toytask->rwsched_tasklet_info, cfsource);
    toyfd->write_context.source.cfsource = NULL;
  }
  // Free the toyfd
  RW_CF_TYPE_FREE(toyfd, rwmsg_toyfd_ptr_t);

  // Return the callback id
  return id;
}
Example #2
0
static void
rwmsg_toysched_io_callback(rwsched_CFSocketRef s,
			   CFSocketCallBackType type,
			   CFDataRef address,
			   const void *data,
			   void *info)
{
  UNUSED(address); UNUSED(data);
  rwsched_instance_ptr_t instance;
  struct rwmsg_toyfd_s *toyfd;
  rwmsg_toytask_t *toytask;
  //static int index = 1;
  int revents = 0;

  // Validate input parameters
  toyfd = (struct rwmsg_toyfd_s *) info;
  RW_CF_TYPE_VALIDATE(toyfd, rwmsg_toyfd_ptr_t);
  toytask = toyfd->toytask;
  RW_CF_TYPE_VALIDATE(toytask, rwtoytask_tasklet_ptr_t);

  // Get the rwsched instance from the toytask
  instance = toytask->toysched->rwsched_instance;
  RW_CF_TYPE_VALIDATE(instance, rwsched_instance_ptr_t);

  // Determine whether this callback represents a read or write toyfd event
  if (type == kCFSocketReadCallBack) {
    revents = POLLIN;
  }
  else if (type == kCFSocketWriteCallBack) {
    revents = POLLOUT;
  }
  else {
    RW_CRASH();
  }

  // Invoke the user specified callback
  RW_ASSERT(toyfd->cb);
  toyfd->cb(toyfd->id, toyfd->fd, revents, toyfd->ud);

  // Inalidate the socket so the callback is not invoked again
  rwsched_tasklet_CFSocketInvalidate(toytask->rwsched_tasklet_info, s);
}
Example #3
0
static void setup_inotify_watcher(rwvx_instance_ptr_t rwvx)
{
  RW_ASSERT(rwvx);

  rwvx->pacemaker_inotify.fd = inotify_init();
  RW_ASSERT(rwvx->pacemaker_inotify.fd >= 0);
  int inotify_wd = inotify_add_watch(
      rwvx->pacemaker_inotify.fd,
      "/tmp/corosync",
      IN_MODIFY);
  RW_ASSERT(inotify_wd >= 0);

  CFSocketContext cf_context = { 0, rwvx, NULL, NULL, NULL };
  CFOptionFlags cf_callback_flags = kCFSocketReadCallBack;
  CFOptionFlags cf_option_flags = kCFSocketAutomaticallyReenableReadCallBack;

  // Release cfsource
  if (rwvx->pacemaker_inotify.cfsource) {
    RW_CF_TYPE_VALIDATE(rwvx->pacemaker_inotify.cfsource, rwsched_CFRunLoopSourceRef);
    rwsched_tasklet_CFSocketReleaseRunLoopSource(
        rwvx->rwsched_tasklet,
        rwvx->pacemaker_inotify.cfsource);
  }
  // Release the cfsocket
  if (rwvx->pacemaker_inotify.cfsocket) {
    RW_CF_TYPE_VALIDATE(rwvx->pacemaker_inotify.cfsocket, rwsched_CFSocketRef);

    // Invalidate the cfsocket
    rwsched_tasklet_CFSocketInvalidate(
        rwvx->rwsched_tasklet,
        rwvx->pacemaker_inotify.cfsocket);

    // Release the cfsocket
    rwsched_tasklet_CFSocketRelease(
        rwvx->rwsched_tasklet,
        rwvx->pacemaker_inotify.cfsocket);
  }

  rwvx->pacemaker_inotify.cfsocket = rwsched_tasklet_CFSocketCreateWithNative(
      rwvx->rwsched_tasklet,
      kCFAllocatorSystemDefault,
      rwvx->pacemaker_inotify.fd,
      cf_callback_flags,
      pacemaker_state_changed,
      &cf_context);
  RW_CF_TYPE_VALIDATE(rwvx->pacemaker_inotify.cfsocket, rwsched_CFSocketRef);

  rwsched_tasklet_CFSocketSetSocketFlags(
      rwvx->rwsched_tasklet,
      rwvx->pacemaker_inotify.cfsocket,
      cf_option_flags);
  
  rwvx->pacemaker_inotify.cfsource = rwsched_tasklet_CFSocketCreateRunLoopSource(
      rwvx->rwsched_tasklet,
      kCFAllocatorSystemDefault,
      rwvx->pacemaker_inotify.cfsocket,
      0);
  RW_CF_TYPE_VALIDATE(rwvx->pacemaker_inotify.cfsource, rwsched_CFRunLoopSourceRef);
  
  rwsched_tasklet_CFRunLoopAddSource(
      rwvx->rwsched_tasklet,
      rwsched_tasklet_CFRunLoopGetCurrent(rwvx->rwsched_tasklet),
      rwvx->pacemaker_inotify.cfsource,
      rwvx->rwsched->main_cfrunloop_mode);
}