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; }
void fqd_remote_client_deref(remote_client *r) { bool zero; ck_pr_dec_uint_zero(&r->refcnt, &zero); fq_debug(FQ_DEBUG_CONN, "deref client -> %u%s\n", r->refcnt, zero ? " dropping" : ""); if(zero) { close(r->fd); free(r); } }
void fq_msg_deref(fq_msg *msg) { bool zero; ck_pr_dec_uint_zero(&msg->refcnt, &zero); if(zero) { #ifdef DEBUG fq_debug(FQ_DEBUG_MSG, "msg(%p) -> free\n", (void *)msg); #endif free(msg); } }