/* And here is how you create an nsock_pool.  This allocates, initializes, and
 * returns an nsock_pool event aggregator.  In the case of error, NULL will be
 * returned.  If you do not wish to immediately associate any userdata, pass in
 * NULL. */
nsock_pool nsp_new(void *userdata) {
  mspool *nsp;

  /* initialize the library in not already done */
  if (!nsocklib_initialized) {
    nsock_library_initialize();
    nsocklib_initialized = 1;
  }

  nsp = (mspool *)safe_malloc(sizeof(*nsp));
  memset(nsp, 0, sizeof(*nsp));

  gettimeofday(&nsock_tod, NULL);

  nsp->loglevel = NSOCK_LOG_ERROR;
  nsp->logger   = (nsock_logger_t)nsock_stderr_logger;

  nsp->id = nsp_next_id++;

  nsp->userdata = userdata;

  nsp->engine = get_io_engine();
  nsock_engine_init(nsp);

  /* initialize IO events lists */
  gh_list_init(&nsp->connect_events);
  gh_list_init(&nsp->read_events);
  gh_list_init(&nsp->write_events);
#if HAVE_PCAP
  gh_list_init(&nsp->pcap_read_events);
#endif

  /* initialize timer heap */
  gh_heap_init(&nsp->expirables, expirable_cmp);

  /* initialize the list of IODs */
  gh_list_init(&nsp->active_iods);

  /* initialize caches */
  gh_list_init(&nsp->free_iods);
  gh_list_init(&nsp->free_events);

  nsp->next_event_serial = 1;

  nsp->device = NULL;

#if HAVE_OPENSSL
  nsp->sslctx = NULL;
#endif

  nsp->px_chain = NULL;

  return (nsock_pool)nsp;
}
Example #2
0
/* And here is how you create an nsock_pool.  This allocates, initializes, and
 * returns an nsock_pool event aggregator.  In the case of error, NULL will be
 * returned.  If you do not wish to immediately associate any userdata, pass in
 * NULL. */
nsock_pool nsp_new(void *userdata) {
  mspool *nsp;

  /* initialize the library in not already done */
  if (!nsocklib_initialized) {
    nsock_library_initialize();
    nsocklib_initialized = 1;
  }

  nsp = (mspool *)safe_malloc(sizeof(*nsp));
  memset(nsp, 0, sizeof(*nsp));

  gettimeofday(&nsock_tod, NULL);
  nsp_settrace(nsp, NULL, 0, NULL);

  nsp->id = nsp_next_id++;

  nsp->userdata = userdata;

  nsp->engine = get_io_engine();
  nsp->engine->init(nsp);

  /* initialize IO events lists */
  gh_list_init(&nsp->connect_events);
  gh_list_init(&nsp->read_events);
  gh_list_init(&nsp->write_events);
#if HAVE_PCAP
  gh_list_init(&nsp->pcap_read_events);
#endif
  /* initialize timer list */
  gh_list_init(&nsp->timer_events);

  /* initialize the list of IODs */
  gh_list_init(&nsp->active_iods);

  /* initialize caches */
  gh_list_init(&nsp->free_iods);
  gh_list_init(&nsp->free_events);

  nsp->next_event_serial = 1;

  nsp->device = NULL;

#if HAVE_OPENSSL
  nsp->sslctx = NULL;
#endif

  return (nsock_pool)nsp;
}