Пример #1
0
static void *
fq_data_worker(void *u) {
  int backoff = 0;
  bool zero;
  fq_conn_s *conn_s = (fq_conn_s *)u;

  ck_pr_inc_uint(&conn_s->thrcnt);

  while(conn_s->stop == 0) {
    if(conn_s->data_ready) {
      if(fq_client_data_connect_internal(conn_s) == 0) {
        backoff = 0; /* we're good, restart our backoff */
      }
      fq_debug(FQ_DEBUG_IO, "[data] connected\n");
      fq_data_worker_loop(conn_s);
      fq_debug(FQ_DEBUG_IO, "[data] connection failed: %s\n", conn_s->error);
    }
    if(backoff) usleep(backoff + (4096 - (lrand48()%8192)));  /* +/- 4ms */
    else backoff = 16384;
    if(backoff < 1000000) backoff += (backoff >> 4);
  }
  if(conn_s->data_fd >= 0) {
    int toclose = conn_s->data_fd;
    conn_s->data_fd = -1;
    fq_debug(FQ_DEBUG_CONN, "close(data_fd)\n");
    close(toclose);
  }

  ck_pr_dec_uint_zero(&conn_s->thrcnt, &zero);
  if(zero) fq_conn_free(conn_s);
  return (void *)NULL;
}
Пример #2
0
static void *
fq_data_worker(void *u) {
  int backoff = 0;
  fq_conn_s *conn_s = (fq_conn_s *)u;
  while(conn_s->stop == 0) {
    if(conn_s->data_ready) {
      if(fq_client_data_connect_internal(conn_s) == 0) {
        backoff = 0; /* we're good, restart our backoff */
      }

      fq_data_worker_loop(conn_s);
#ifdef DEBUG
      fq_debug(FQ_DEBUG_IO, "[data] connection failed: %s\n", conn_s->error);
#endif
    }
    if(backoff < 1000000) backoff += 10000;
    if(backoff) usleep(backoff);
  }
  if(conn_s->data_fd >= 0) {
    close(conn_s->data_fd);
    conn_s->data_fd = -1;
  }
  return (void *)NULL;
}