In/out reference counting.

This commit is contained in:
Ian Gulliver
2016-02-25 16:17:25 -08:00
parent aa940137c1
commit 5e604f0596
9 changed files with 35 additions and 12 deletions

View File

@@ -26,6 +26,7 @@ struct outgoing {
uint32_t attempt;
outgoing_connection_handler handler;
void *passthrough;
uint32_t *count;
struct outgoing *next;
};
@@ -134,6 +135,7 @@ static void outgoing_resolve_wrapper(struct peer *peer) {
}
static void outgoing_del(struct outgoing *outgoing) {
(*outgoing->count)--;
if (outgoing->peer.fd >= 0) {
assert(!close(outgoing->peer.fd));
}
@@ -151,7 +153,9 @@ void outgoing_cleanup() {
}
}
void outgoing_new(char *node, char *service, outgoing_connection_handler handler, void *passthrough) {
void outgoing_new(char *node, char *service, outgoing_connection_handler handler, void *passthrough, uint32_t *count) {
(*count)++;
struct outgoing *outgoing = malloc(sizeof(*outgoing));
uuid_gen(outgoing->id);
outgoing->node = strdup(node);
@@ -159,6 +163,7 @@ void outgoing_new(char *node, char *service, outgoing_connection_handler handler
outgoing->attempt = 0;
outgoing->handler = handler;
outgoing->passthrough = passthrough;
outgoing->count = count;
outgoing->next = outgoing_head;
outgoing_head = outgoing;