Skip to content

Commit

Permalink
add sock->release_user_data and use in in process.c
Browse files Browse the repository at this point in the history
Signed-off-by: Olaf Hering <olaf@aepfle.de>
  • Loading branch information
olafhering committed Feb 14, 2014
1 parent 2dc503d commit 66e661d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/process.c
Expand Up @@ -553,6 +553,14 @@ __ni_process_output_hangup(ni_socket_t *sock)
}
}

static void
__ni_process_release_user_data(void *user_data)
{
ni_process_t *pi = user_data;
if (pi)
ni_process_free(pi);
}

static ni_socket_t *
__ni_process_get_output(ni_process_t *pi, int fd)
{
Expand All @@ -562,6 +570,7 @@ __ni_process_get_output(ni_process_t *pi, int fd)
sock->receive = __ni_process_output_recv;
sock->handle_hangup = __ni_process_output_hangup;

sock->release_user_data = __ni_process_release_user_data;
sock->user_data = pi;
return sock;
}
Expand Down
2 changes: 2 additions & 0 deletions src/socket.c
Expand Up @@ -91,6 +91,8 @@ ni_socket_release(ni_socket_t *sock)
if (sock->refcount == 0) {
__ni_socket_close(sock);
ni_assert(!sock->active);
if (sock->release_user_data)
sock->release_user_data(sock->user_data);
free(sock);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/socket_priv.h
Expand Up @@ -36,6 +36,7 @@ struct ni_socket {
int (*get_timeout)(const ni_socket_t *, struct timeval *);
void (*check_timeout)(ni_socket_t *, const struct timeval *);

void (*release_user_data)(void *);
void * user_data;
};

Expand Down

0 comments on commit 66e661d

Please sign in to comment.