home *** CD-ROM | disk | FTP | other *** search
/ ftp.parl.clemson.edu / 2015-02-07.ftp.parl.clemson.edu.tar / ftp.parl.clemson.edu / pub / pvfs2 / orangefs-2.8.3-20110323.tar.gz / orangefs-2.8.3-20110323.tar / orangefs / src / io / flow / flow-ref.c < prev    next >
C/C++ Source or Header  |  2004-07-28  |  3KB  |  137 lines

  1. /*
  2.  * (C) 2001 Clemson University and The University of Chicago
  3.  *
  4.  * See COPYING in top-level directory.
  5.  */
  6.  
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include <errno.h>
  10.  
  11. #include "flow-ref.h"
  12.  
  13. /* flow_ref_new()
  14.  *
  15.  * creates a new linked list to keep up with flow protocol
  16.  *
  17.  * returns pointer to flow reference list on success, NULL on failure
  18.  */
  19. flow_ref_p flow_ref_new(void)
  20. {
  21.     struct qlist_head *tmp_frp = NULL;
  22.  
  23.     tmp_frp = (struct qlist_head *) malloc(sizeof(struct qlist_head));
  24.     if (tmp_frp)
  25.     {
  26.     INIT_QLIST_HEAD(tmp_frp);
  27.     }
  28.  
  29.     return (tmp_frp);
  30. }
  31.  
  32. /* flow_ref_add()
  33.  *
  34.  * adds a new entry to the flow reference list
  35.  * 
  36.  * no return value
  37.  */
  38. int flow_ref_add(flow_ref_p frp,
  39.          enum flow_endpoint_type src_endpoint,
  40.          enum flow_endpoint_type dest_endpoint,
  41.          int flowproto_id)
  42. {
  43.     struct flow_ref_entry *tmp_entry = NULL;
  44.  
  45.     tmp_entry = (struct flow_ref_entry *) malloc(sizeof(struct flow_ref_entry));
  46.     if (!tmp_entry)
  47.     {
  48.     return (-ENOMEM);
  49.     }
  50.  
  51.     tmp_entry->src_endpoint = src_endpoint;
  52.     tmp_entry->dest_endpoint = dest_endpoint;
  53.     tmp_entry->flowproto_id = flowproto_id;
  54.  
  55.     qlist_add(&(tmp_entry->flow_ref_link), frp);
  56.  
  57.     return (0);
  58. }
  59.  
  60. /* flow_ref_search()
  61.  *
  62.  * searches for a flow reference entry based on src and dest endpoints
  63.  *
  64.  * returns pointer to entry if found, NULL otherwise
  65.  */
  66. struct flow_ref_entry *flow_ref_search(flow_ref_p frp,
  67.                        enum flow_endpoint_type src_endpoint,
  68.                        enum flow_endpoint_type dest_endpoint)
  69. {
  70.     flow_ref_p tmp_link = NULL;
  71.     flow_ref_p tmp_next_link = NULL;
  72.     struct flow_ref_entry *tmp_entry = NULL;
  73.  
  74.     tmp_link = frp->next;
  75.     tmp_next_link = tmp_link->next;
  76.     while (tmp_link != frp)
  77.     {
  78.     tmp_entry = qlist_entry(tmp_link, struct flow_ref_entry,
  79.                 flow_ref_link);
  80.     if (tmp_entry->src_endpoint == src_endpoint &&
  81.         tmp_entry->dest_endpoint == dest_endpoint)
  82.     {
  83.         return (tmp_entry);
  84.     }
  85.     tmp_link = tmp_next_link;
  86.     tmp_next_link = tmp_link->next;
  87.     }
  88.  
  89.     return (NULL);
  90. }
  91.  
  92. /* flow_ref_remove()
  93.  *
  94.  * removes a flow reference entry
  95.  *
  96.  * no return value
  97.  */
  98. void flow_ref_remove(struct flow_ref_entry *entry)
  99. {
  100.     qlist_del(&(entry->flow_ref_link));
  101.     return;
  102. }
  103.  
  104.  
  105. /* flow_ref_cleanup()
  106.  *
  107.  * destroys a flow reference linked list and all of its entries
  108.  *
  109.  * no return value
  110.  */
  111. void flow_ref_cleanup(flow_ref_p frp)
  112. {
  113.     flow_ref_p iterator = NULL;
  114.     flow_ref_p scratch = NULL;
  115.     struct flow_ref_entry *tmp_entry = NULL;
  116.  
  117.     qlist_for_each_safe(iterator, scratch, frp)
  118.     {
  119.     tmp_entry = qlist_entry(iterator, struct flow_ref_entry,
  120.                 flow_ref_link);
  121.     free(tmp_entry);
  122.     }
  123.  
  124.     free(frp);
  125.     frp = NULL;
  126.     return;
  127. }
  128.  
  129. /*
  130.  * Local variables:
  131.  *  c-indent-level: 4
  132.  *  c-basic-offset: 4
  133.  * End:
  134.  *
  135.  * vim: ts=8 sts=4 sw=4 expandtab
  136.  */
  137.