ext/iodine/fio.c
/* resets connection data, marking it as either open or closed. */
resets connection data, marking it as either open or closed.
resets connection data marking it as either open or closed .
static inline int fio_clear_fd(intptr_t fd, uint8_t is_open) {
  fio_packet_s *packet;
  fio_protocol_s *protocol;
  fio_rw_hook_s *rw_hooks;
  void *rw_udata;
  fio_uuid_links_s links;
  fio_lock(&(fd_data(fd).sock_lock));
  links = fd_data(fd).links;
  packet = fd_data(fd).packet;
  protocol = fd_data(fd).protocol;
  rw_hooks = fd_data(fd).rw_hooks;
  rw_udata = fd_data(fd).rw_udata;
  fd_data(fd) = (fio_fd_data_s){
      .open = is_open,
      .sock_lock = fd_data(fd).sock_lock,
      .protocol_lock = fd_data(fd).protocol_lock,
      .rw_hooks = (fio_rw_hook_s *)&FIO_DEFAULT_RW_HOOKS,
      .counter = fd_data(fd).counter + 1,
      .packet_last = &fd_data(fd).packet,
  };
  if (fio_data->max_protocol_fd < fd) {
    fio_data->max_protocol_fd = fd;
  } else {
    while (fio_data->max_protocol_fd &&
           !fd_data(fio_data->max_protocol_fd).open)
      --fio_data->max_protocol_fd;
  }
  fio_unlock(&(fd_data(fd).sock_lock));
  if (rw_hooks && rw_hooks->cleanup)
    rw_hooks->cleanup(rw_udata);
  while (packet) {
    fio_packet_s *tmp = packet;
    packet = packet->next;
    fio_packet_free(tmp);
  }
  if (fio_uuid_links_count(&links)) {
    FIO_SET_FOR_LOOP(&links, pos) {
      if (pos->hash)
        pos->obj((void *)pos->hash);
    }
  }
  fio_uuid_links_free(&links);
  if (protocol && protocol->on_close) {
    fio_defer(deferred_on_close, (void *)fd2uuid(fd), protocol);
  }
  FIO_LOG_DEBUG("FD %d re-initialized (state: %p-%s).", (int)fd,
                (void *)fd2uuid(fd), (is_open ? "open" : "closed"));
  return 0;
}
static inline int fio_clear_fd ( intptr_t fd , uint8_t is_open ) { fio_packet_s * packet ; fio_protocol_s * protocol ; fio_rw_hook_s * rw_hooks ; void * rw_udata ; fio_uuid_links_s links ; fio_lock ( & ( fd_data ( fd ) . sock_lock ) ) ; links = fd_data ( fd ) . links ; packet = fd_data ( fd ) . packet ; protocol = fd_data ( fd ) . protocol ; rw_hooks = fd_data ( fd ) . rw_hooks ; rw_udata = fd_data ( fd ) . rw_udata ; fd_data ( fd ) = ( fio_fd_data_s ) { . open = is_open , . sock_lock = fd_data ( fd ) . sock_lock , . protocol_lock = fd_data ( fd ) . protocol_lock , . rw_hooks = ( fio_rw_hook_s * ) & FIO_DEFAULT_RW_HOOKS , . counter = fd_data ( fd ) . counter + 1 , . packet_last = & fd_data ( fd ) . packet , } ; if ( fio_data -> max_protocol_fd < fd ) { fio_data -> max_protocol_fd = fd ; } else { while ( fio_data -> max_protocol_fd && ! fd_data ( fio_data -> max_protocol_fd ) . open ) -- fio_data -> max_protocol_fd ; } fio_unlock ( & ( fd_data ( fd ) . sock_lock ) ) ; if ( rw_hooks && rw_hooks -> cleanup ) rw_hooks -> cleanup ( rw_udata ) ; while ( packet ) { fio_packet_s * tmp = packet ; packet = packet -> next ; fio_packet_free ( tmp ) ; } if ( fio_uuid_links_count ( & links ) ) { FIO_SET_FOR_LOOP ( & links , pos ) { if ( pos -> hash ) pos -> obj ( ( void * ) pos -> hash ) ; } } fio_uuid_links_free ( & links ) ; if ( protocol && protocol -> on_close ) { fio_defer ( deferred_on_close , ( void * ) fd2uuid ( fd ) , protocol ) ; } FIO_LOG_DEBUG ( " " , ( int ) fd , ( void * ) fd2uuid ( fd ) , ( is_open ? " " : " " ) ) ; return 0 ; }
resets connection data, marking it as either open or closed.
resets connection data marking it as either open or closed .