Пример #1
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;
  nsp = (mspool *) safe_malloc(sizeof(*nsp));
  memset(nsp, 0, sizeof(*nsp));

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

  nsp->broadcast = 0;
  if (!nsocklib_initialized) {
    nsock_library_initialize();
    nsocklib_initialized = 1;
  }

  nsp->id = nsp_next_id++;

  /* Now to init the nsock_io_info */
  FD_ZERO(&nsp->mioi.fds_master_r);
  FD_ZERO(&nsp->mioi.fds_master_w);
  FD_ZERO(&nsp->mioi.fds_master_x);
  nsp->mioi.max_sd = -1;
  nsp->mioi.results_left = 0;

  /* Next comes the event list structure */
  gh_list_init(&nsp->evl.connect_events);
  gh_list_init(&nsp->evl.read_events);
  gh_list_init(&nsp->evl.write_events);
  gh_list_init(&nsp->evl.timer_events);
  #if HAVE_PCAP
  gh_list_init(&nsp->evl.pcap_read_events);
  #endif 
  gh_list_init(&nsp->evl.free_events);
  nsp->evl.next_ev.tv_sec = 0;
  nsp->evl.events_pending = 0;

  nsp->userdata = userdata;

  gh_list_init(&nsp->free_iods);
  gh_list_init(&nsp->active_iods);
  nsp->next_event_serial = 1;

  nsp->quit = 0;

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

  return (nsock_pool) nsp;
}
Пример #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;
}