ext/iodine/fio.c
/** Sets a socket hook state (a pointer to the struct). */
Sets a socket hook state (a pointer to the struct).
Sets a socket hook state ( a pointer to the struct ) .
int fio_rw_hook_set(intptr_t uuid, fio_rw_hook_s *rw_hooks, void *udata) {
  if (fio_is_closed(uuid))
    goto invalid_uuid;
  fio_rw_hook_validate(rw_hooks);
  intptr_t fd = fio_uuid2fd(uuid);
  fio_rw_hook_s *old_rw_hooks;
  void *old_udata;
  fio_lock(&fd_data(fd).sock_lock);
  if (fd2uuid(fd) != uuid) {
    fio_unlock(&fd_data(fd).sock_lock);
    goto invalid_uuid;
  }
  old_rw_hooks = fd_data(fd).rw_hooks;
  old_udata = fd_data(fd).rw_udata;
  fd_data(fd).rw_hooks = rw_hooks;
  fd_data(fd).rw_udata = udata;
  fio_unlock(&fd_data(fd).sock_lock);
  if (old_rw_hooks && old_rw_hooks->cleanup)
    old_rw_hooks->cleanup(old_udata);
  return 0;
invalid_uuid:
  if (!rw_hooks->cleanup)
    rw_hooks->cleanup(udata);
  return -1;
}
int fio_rw_hook_set ( intptr_t uuid , fio_rw_hook_s * rw_hooks , void * udata ) { if ( fio_is_closed ( uuid ) ) goto invalid_uuid ; fio_rw_hook_validate ( rw_hooks ) ; intptr_t fd = fio_uuid2fd ( uuid ) ; fio_rw_hook_s * old_rw_hooks ; void * old_udata ; fio_lock ( & fd_data ( fd ) . sock_lock ) ; if ( fd2uuid ( fd ) != uuid ) { fio_unlock ( & fd_data ( fd ) . sock_lock ) ; goto invalid_uuid ; } old_rw_hooks = fd_data ( fd ) . rw_hooks ; old_udata = fd_data ( fd ) . rw_udata ; fd_data ( fd ) . rw_hooks = rw_hooks ; fd_data ( fd ) . rw_udata = udata ; fio_unlock ( & fd_data ( fd ) . sock_lock ) ; if ( old_rw_hooks && old_rw_hooks -> cleanup ) old_rw_hooks -> cleanup ( old_udata ) ; return 0 ; invalid_uuid : if ( ! rw_hooks -> cleanup ) rw_hooks -> cleanup ( udata ) ; return -1 ; }
Sets a socket hook state (a pointer to the struct).
Sets a socket hook state ( a pointer to the struct ) .