agoo_con_destroy(agooCon c) {
    atomic_fetch_sub(&agoo_server.con_cnt, 1);
    if (AGOO_CON_WS == c->bind->kind || AGOO_CON_SSE == c->bind->kind) {
	agoo_ws_req_close(c);
    }
    if (0 < c->sock) {
#ifdef HAVE_OPENSSL_SSL_H
	if (NULL != c->ssl) {
	    SSL_free(c->ssl);
	    c->ssl = NULL;
	}
#endif
	close(c->sock);
	c->sock = 0;
    }
    if (NULL != c->req) {
	agoo_req_destroy(c->req);
    }
    if (NULL != c->up) {
	agoo_upgraded_release_con(c->up);
	c->up = NULL;
    }
    if (NULL != c->gsub) {
	agoo_server_del_gsub(c->gsub);
	gql_sub_destroy(c->gsub);
	c->gsub = NULL;
    }
    agoo_log_cat(&agoo_con_cat, "Connection %llu closed.", (unsigned long long)c->id);

    agooRes	res;

    while (NULL != (res = c->res_head)) {
	c->res_head = res->next;
	AGOO_FREE(res);
    }
    pthread_mutex_destroy(&c->res_lock);
    AGOO_FREE(c);
}
agoo_con_destroy(agooCon c) {
    atomic_fetch_sub(&agoo_server.con_cnt, 1);
    if (AGOO_CON_WS == c->bind->kind || AGOO_CON_SSE == c->bind->kind) {
	agoo_ws_req_close(c);
    }
    if (0 < c->sock) {
#ifdef HAVE_OPENSSL_SSL_H
	if (NULL != c->ssl) {
	    SSL_free(c->ssl);
	    c->ssl = NULL;
	}
#endif
	close(c->sock);
	c->sock = 0;
    }
    if (NULL != c->req) {
	agoo_req_destroy(c->req);
    }
    if (NULL != c->up) {
	agoo_upgraded_release_con(c->up);
	c->up = NULL;
    }
    if (NULL != c->gsub) {
	agoo_server_del_gsub(c->gsub);
	gql_sub_destroy(c->gsub);
	c->gsub = NULL;
    }
    agoo_log_cat(&agoo_con_cat, "Connection %llu closed.", (unsigned long long)c->id);

    agooRes	res;

    while (NULL != (res = c->res_head)) {
	c->res_head = res->next;
	AGOO_FREE(res);
    }
    pthread_mutex_destroy(&c->res_lock);
    AGOO_FREE(c);
}