-/* After clients create a monitor, use this to add it to the collection.
- Returns 0 on success, -1 otherwise. */
-int insert_tcp_port_monitor_into_collection(
- tcp_port_monitor_collection_t * p_collection,
- tcp_port_monitor_t * p_monitor
- )
-{
- tcp_port_monitor_node_t * p_node;
-
- if ( !p_collection || !p_monitor )
- return (-1);
-
- /* create a container node for this monitor */
- p_node = (tcp_port_monitor_node_t *) calloc( 1, sizeof(tcp_port_monitor_node_t) );
- if ( !p_node )
- return (-1);
-
- /* populate the node */
- p_node->p_monitor = p_monitor;
- p_node->p_next = NULL;
-
- /* add a pointer to this monitor to the collection's hash */
- if ( hash_insert( &p_collection->hash, (void *)p_monitor ) != 0 )
- {
- /* error inserting into hash. destroy the monitor's container node so no leaks */
- free( p_node );
- return (-1);
- }
-
- /* tail of the container gets this node */
- if ( !p_collection->monitor_list.p_tail )
- p_collection->monitor_list.p_tail = p_node;
- else
- {
- /* p_next of the tail better be NULL */
- if ( p_collection->monitor_list.p_tail->p_next != NULL )
- return (-1);
-
- /* splice node onto tail */
- p_collection->monitor_list.p_tail->p_next = p_node;
- p_collection->monitor_list.p_tail = p_node;
- }
-
- /* if this was the first element added */
- if ( !p_collection->monitor_list.p_head )
- p_collection->monitor_list.p_head = p_collection->monitor_list.p_tail;
-
- return 0;