]> sjero.net Git - iperf/blob - src/List.cpp
8cba006dcd9c0ee7016439d70d17b3d223a0f6ed
[iperf] / src / List.cpp
1
2 /*--------------------------------------------------------------- 
3  * Copyright (c) 1999,2000,2001,2002,2003                              
4  * The Board of Trustees of the University of Illinois            
5  * All Rights Reserved.                                           
6  *--------------------------------------------------------------- 
7  * Permission is hereby granted, free of charge, to any person    
8  * obtaining a copy of this software (Iperf) and associated       
9  * documentation files (the "Software"), to deal in the Software  
10  * without restriction, including without limitation the          
11  * rights to use, copy, modify, merge, publish, distribute,        
12  * sublicense, and/or sell copies of the Software, and to permit     
13  * persons to whom the Software is furnished to do
14  * so, subject to the following conditions: 
15  *
16  *     
17  * Redistributions of source code must retain the above 
18  * copyright notice, this list of conditions and 
19  * the following disclaimers. 
20  *
21  *     
22  * Redistributions in binary form must reproduce the above 
23  * copyright notice, this list of conditions and the following 
24  * disclaimers in the documentation and/or other materials 
25  * provided with the distribution. 
26  * 
27  *     
28  * Neither the names of the University of Illinois, NCSA, 
29  * nor the names of its contributors may be used to endorse 
30  * or promote products derived from this Software without
31  * specific prior written permission. 
32  * 
33  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
34  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
35  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
36  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTIBUTORS OR COPYRIGHT 
37  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
38  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
39  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE
40  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
41  * ________________________________________________________________
42  * National Laboratory for Applied Network Research 
43  * National Center for Supercomputing Applications 
44  * University of Illinois at Urbana-Champaign 
45  * http://www.ncsa.uiuc.edu
46  * ________________________________________________________________ 
47  *
48  * List.cpp
49  * by Kevin Gibbs <kgibbs@ncsa.uiuc.edu> 
50  * ------------------------------------------------------------------- 
51  */
52
53 #include "List.h"
54 #include "Mutex.h"
55 #include "SocketAddr.h"
56
57 /*
58  * Global List and Mutex variables
59  */
60 Iperf_ListEntry *clients = NULL;
61 Mutex clients_mutex; 
62
63 /*
64  * Add Entry add to the List
65  */
66 void Iperf_pushback ( Iperf_ListEntry *add, Iperf_ListEntry **root ) {
67     add->next = *root;
68     *root = add;
69 }
70
71 /*
72  * Delete Entry del from the List
73  */
74 void Iperf_delete ( iperf_sockaddr *del, Iperf_ListEntry **root ) {
75     Iperf_ListEntry *temp = Iperf_present( del, *root );
76     if ( temp != NULL ) {
77         if ( temp == *root ) {
78             *root = (*root)->next;
79         } else {
80             Iperf_ListEntry *itr = *root;
81             while ( itr->next != NULL ) {
82                 if ( itr->next == temp ) {
83                     itr->next = itr->next->next;
84                     break;
85                 }
86                 itr = itr->next;
87             }
88         }
89         delete temp;
90     }
91 }
92
93 /*
94  * Destroy the List (cleanup function)
95  */
96 void Iperf_destroy ( Iperf_ListEntry **root ) {
97     Iperf_ListEntry *itr1 = *root, *itr2;
98     while ( itr1 != NULL ) {
99         itr2 = itr1->next;
100         delete itr1;
101         itr1 = itr2;
102     }
103     *root = NULL;
104 }
105
106 /*
107  * Check if the exact Entry find is present
108  */
109 Iperf_ListEntry* Iperf_present ( iperf_sockaddr *find, Iperf_ListEntry *root ) {
110     Iperf_ListEntry *itr = root;
111     while ( itr != NULL ) {
112         if ( SockAddr_are_Equal( (sockaddr*)itr, (sockaddr*)find ) ) {
113             return itr;
114         }
115         itr = itr->next;
116     }
117     return NULL;
118 }
119
120 /*
121  * Check if a Entry find is in the List or if any
122  * Entry exists that has the same host as the 
123  * Entry find
124  */
125 Iperf_ListEntry* Iperf_hostpresent ( iperf_sockaddr *find, Iperf_ListEntry *root ) {
126     Iperf_ListEntry *itr = root;
127     while ( itr != NULL ) {
128         if ( SockAddr_Hostare_Equal( (sockaddr*)itr, (sockaddr*)find ) ) {
129             return itr;
130         }
131         itr = itr->next;
132     }
133     return NULL;
134 }