Main Page | Data Structures | File List | Data Fields | Globals | Related Pages

connlist.c File Reference

Functions to help search and maintain the connection list. These functions are thread-safe. More...

#include "connlist.h"
#include <pthread.h>
#include "debug.h"
#include <unistd.h>

Go to the source code of this file.

Functions

errorcode connlist_init (connlist_t *list)
 the function to initialize the list
errorcode connlist_add (connlist_t *list, connlist_item_t *item)
 the function to add an item to the list
errorcode connlist_find (connlist_t *list, int(*func)(void *, void *), void *arg, connlist_item_t **found_item)
 finds an item in the list
int connlist_find_pred_port (void *this_item, void *find_item)
 the function to find a predictied port match (used as a match function for the list implementation).
int connlist_find_buddy (void *this_item, void *find_item)
 the function to find a buddy match (used as a match function for the list implementation).
errorcode connlist_forget (connlist_t *list, int(*func)(void *, void *), connlist_item_t *item)
 the function to remove an item from the list
int connlist_item_match (void *this_item, void *find_item)
 the matching function for an item in the list
int connlist_count (connlist_t *list)
 gets the number of items in the list


Detailed Description

Functions to help search and maintain the connection list. These functions are thread-safe.

Author:
Daniel Ferullo (ferullo@cmu.edu)

Definition in file connlist.c.


Function Documentation

errorcode connlist_add connlist_t list,
connlist_item_t item
 

the function to add an item to the list

This function is thread safe. forget must be called once for this function to remove the item from the list once it has been added.

Parameters:
list pointer to the connlist_t list
item pointer to the item to add
Returns:
SUCCESS, errorcode on failure

Definition at line 49 of file connlist.c.

References CHECK_NOT_NULL, connlist_item_t, connlist_t, DBG_THREAD, DEBUG, ERROR_NULL_ARG_1, ERROR_NULL_ARG_2, errorcode, FAILED, connlist::list, list_add(), connlist::mutex, and connlist_item::watchers.

Referenced by helper_fsm_start().

int connlist_count connlist_t list  ) 
 

gets the number of items in the list

This function is thread safe

Parameters:
list pointer to the connlist
Returns:
the number of elements, negative on error

Definition at line 238 of file connlist.c.

References CHECK_NOT_NULL, connlist_t, DBG_THREAD, DEBUG, connlist::list, list_count(), and connlist::mutex.

Referenced by natblaster_server().

errorcode connlist_find connlist_t list,
int(*)(void *, void *)  func,
void *  arg,
connlist_item_t **  found_item
 

finds an item in the list

This function is thread safe

Parameters:
list pointer to the connlist_t list
func function pointer to use in find matching. Function must meet requirements specified for function list_find in list.h
arg the one optional argument passed into the func function
found_item pointer to a void* to fill in with the found item. On error this value is undefined.
Returns:
SUCCESS, errorcode on failure

Definition at line 79 of file connlist.c.

References CHECK_NOT_NULL, connlist_item_t, connlist_t, DBG_PORT_PRED, DBG_THREAD, DEBUG, ERROR_NULL_ARG_1, ERROR_NULL_ARG_2, ERROR_NULL_ARG_4, errorcode, FAILED, connlist::list, list_find(), connlist::mutex, and connlist_item::watchers.

Referenced by find_conn2(), and get_buddy().

int connlist_find_buddy void *  this_item,
void *  find_item
 

the function to find a buddy match (used as a match function for the list implementation).

Parameters:
this_item the item from the list to check (a connlist_item_t pointer)
find_item the values to match on (a buddy_info_t pointer)
Returns:
LIST_FATAL, LIST_FOUND, LIST_NOT_FOUND, as per requirements

Definition at line 151 of file connlist.c.

References buddy_info_t, CHECK_NOT_NULL, connlist_item_t, buddy_info::ext_ip, connlist_item::info, buddy_info::int_ip, buddy_info::int_port, peer_info::ip, observed_data::ip, LIST_FATAL, connlist_item::obs_data, helper_conn_info::peer, and peer_info::port.

Referenced by get_buddy().

int connlist_find_pred_port void *  this_item,
void *  find_item
 

the function to find a predictied port match (used as a match function for the list implementation).

Parameters:
this_item the item from the list to check (a connlist_item_t pointer)
find_item the values to match on (an observed_data_t pointer)
Returns:
LIST_FATAL, LIST_FOUND, LIST_NOT_FOUND, as per requirements

Definition at line 121 of file connlist.c.

References CHECK_NOT_NULL, connlist_item_t, DBG_IP, DBG_PORT, DBG_PORT_PRED, DEBUG, observed_data::ip, LIST_FATAL, connlist_item::obs_data, observed_data_t, and observed_data::port.

Referenced by find_conn2().

errorcode connlist_forget connlist_t list,
int(*)(void *, void *)  func,
connlist_item_t item
 

the function to remove an item from the list

This function is thread safe.

This function will only remove the item if there are no watchers left. It must be called exactly once for each time find is called, plus once more for the add call.

Parameters:
list a pointer to the list to remove from
func the function to use in matching for the forget
item a pointer to the item to remove
Returns:
SUCCESS, errorcode on failure

Definition at line 187 of file connlist.c.

References CHECK_NOT_NULL, connlist_item_t, connlist_t, DBG_THREAD, DEBUG, ERROR_NULL_ARG_1, ERROR_NULL_ARG_2, errorcode, FAILED, connlist::list, list_remove(), connlist::mutex, and connlist_item::watchers.

Referenced by helper_fsm_buddy_alloc(), helper_fsm_conn2(), and helper_fsm_start().

errorcode connlist_init connlist_t list  ) 
 

the function to initialize the list

man page says return value is always 0, but I don't trust it, since the man page for pthreads also says some functions/macros exist that in fact do not.

Definition at line 32 of file connlist.c.

References CHECK_FAILED, CHECK_NOT_NULL, connlist_t, ERROR_INIT, ERROR_NULL_ARG_1, errorcode, connlist::list, list_init(), and connlist::mutex.

Referenced by natblaster_server().

int connlist_item_match void *  this_item,
void *  find_item
 

the matching function for an item in the list

Parameters:
this_item a pointer to the current item in the list (will be cast to a connlist_t pointer)
find_item a pointer to the item to find (will be cast to a connlist_item_t pointer)
Returns:
LIST_FATAL, LIST_FOUND, LIST_NOT_FOUND as list.h requires

Definition at line 223 of file connlist.c.

References CHECK_NOT_NULL, and LIST_FATAL.

Referenced by helper_fsm_buddy_alloc(), helper_fsm_conn2(), and helper_fsm_start().


Generated on Wed Mar 30 23:20:47 2005 for NATBLASTER by  doxygen 1.3.9.1