예제 #1
0
void rb_http_handler_run(struct rb_http_handler_s *rb_http_handler) {
  assert(rb_http_handler != NULL);
  assert(rb_http_handler->options != NULL);

  int i = 0;
  struct rb_http_threaddata_s *rb_http_threaddata = NULL;

  switch (rb_http_handler->options->mode) {
  case NORMAL_MODE:
  default:
    rb_http_threaddata = calloc(1, sizeof(struct rb_http_threaddata_s));
    rb_http_handler->threads[0] = rb_http_threaddata;

    rd_fifoq_init(&rb_http_threaddata->rfq);
    rd_fifoq_init(&rb_http_handler->rfq_reports);
    rb_http_threaddata->rfq_pending = NULL;
    rb_http_threaddata->rb_http_handler = rb_http_handler;
    rb_http_threaddata->opaque = NULL;
    rb_http_handler->options->max_batch_messages =
        rb_http_handler->options->max_messages / 10;
    rb_http_handler->multi_handle = curl_multi_init();

    curl_multi_setopt(rb_http_handler->multi_handle,
                      CURLMOPT_MAX_TOTAL_CONNECTIONS,
                      rb_http_handler->options->connections);
    pthread_create(&rb_http_threaddata->p_thread, NULL, &rb_http_process_normal,
                   rb_http_threaddata);
    break;
  case CHUNKED_MODE:
    for (i = 0; i < rb_http_handler->options->connections; i++) {
      rb_http_threaddata = calloc(1, sizeof(struct rb_http_threaddata_s));
      rb_http_handler->threads[i] = rb_http_threaddata;
      rb_http_handler->options->max_batch_messages =
          rb_http_handler->options->max_messages / 10;
      rb_http_handler->options->post_timeout =
          rb_http_handler->options->batch_timeout;

      rd_fifoq_init(&rb_http_threaddata->rfq);
      rb_http_threaddata->post_timestamp = time(NULL);
      rb_http_threaddata->rfq_pending = NULL;
      rb_http_threaddata->rb_http_handler = rb_http_handler;
      rb_http_threaddata->easy_handle = curl_easy_init();
      rb_http_threaddata->chunks = 0;
      rb_http_threaddata->opaque = NULL;

      if (rb_http_handler->options->insecure) {
        curl_easy_setopt(rb_http_threaddata->easy_handle,
                         CURLOPT_SSL_VERIFYPEER, 0);
        curl_easy_setopt(rb_http_threaddata->easy_handle,
                         CURLOPT_SSL_VERIFYHOST, 0);
      }

      pthread_create(&rb_http_threaddata->p_thread, NULL,
                     &rb_http_process_chunked, rb_http_threaddata);
    }
    break;
  }
}
예제 #2
0
struct rb_http_handler_s *rb_http_handler_create(const char *urls_str,
                                                 char *err, size_t errsize) {

  (void)err;
  (void)errsize;

  if (urls_str == NULL)
    return NULL;

  struct rb_http_handler_s *rb_http_handler =
      calloc(1, sizeof(struct rb_http_handler_s));

  rb_http_handler->options = calloc(1, sizeof(struct rb_http_options_s));

  rd_fifoq_init(&rb_http_handler->rfq_reports);

  rb_http_handler->still_running = 0;
  rb_http_handler->msgs_left = 0;
  rb_http_handler->thread_running = 1;

  rb_http_handler->options->max_messages = DEFAULT_MAX_MESSAGES;
  rb_http_handler->options->conntimeout = DEFAULT_CONTTIMEOUT;
  rb_http_handler->options->connections = DEFAULT_CONNECTIONS;
  rb_http_handler->options->timeout = DEFAULT_TIMEOUT;
  rb_http_handler->options->url = strdup(urls_str);
  rb_http_handler->options->mode = NORMAL_MODE;
  rb_http_handler->options->insecure = 0;

  curl_global_init(CURL_GLOBAL_ALL);

  return rb_http_handler;
}
예제 #3
0
파일: rdthread.c 프로젝트: edenhill/librd
rd_thread_t *rd_thread_create0 (const char *name, pthread_t *pthread) {
    rd_thread_t *rdt;

    rdt = calloc(1, sizeof(*rdt));

    if (name)
        rdt->rdt_name = strdup(name);

    rdt->rdt_state = RD_THREAD_S_RUNNING;

    rd_fifoq_init(&rdt->rdt_eventq);

    if (pthread)
        rdt->rdt_thread = *pthread;

    return rdt;
}