1 /** \file alc_list.h \brief Receive packets to the list
2  *
3  *  $Author: peltotal $ $Date: 2007/02/26 13:48:19 $ $Revision: 1.10 $
4  *
5  *  MAD-ALCLIB: Implementation of ALC/LCT protocols, Compact No-Code FEC,
6  *  Simple XOR FEC, Reed-Solomon FEC, and RLC Congestion Control protocol.
7  *  Copyright (c) 2003-2007 TUT - Tampere University of Technology
8  *  main authors/contacts: jani.peltotalo@tut.fi and sami.peltotalo@tut.fi
9  *
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 2 of the License, or
13  *  (at your option) any later version.
14  *
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program; if not, write to the Free Software
22  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23  *
24  *  In addition, as a special exception, TUT - Tampere University of Technology
25  *  gives permission to link the code of this program with the OpenSSL library (or
26  *  with modified versions of OpenSSL that use the same license as OpenSSL), and
27  *  distribute linked combinations including the two. You must obey the GNU
28  *  General Public License in all respects for all of the code used other than
29  *  OpenSSL. If you modify this file, you may extend this exception to your version
30  *  of the file, but you are not obligated to do so. If you do not wish to do so,
31  *  delete this exception statement from your version.
32  */
33 
34 #ifndef _ALCLIST_H_
35 #define _ALCLIST_H_
36 
37 #ifdef _MSC_VER
38 #include <winsock2.h>
39 #else
40 #include <pthread.h>
41 #include <sys/socket.h>
42 #include <sys/time.h>
43 #endif
44 
45 #include "defines.h"
46 
47 /**
48  * Container which stores received packet and its information.
49  * @struct alc_rcv_container
50  */
51 
52 typedef struct alc_rcv_container {
53     char recvbuf[MAX_PACKET_LENGTH]; /**< buffer for the received data */
54     struct sockaddr_storage from;	/**< information about sender of the packet */
55 
56 #ifdef _MSC_VER
57     int fromlen;					/**< the actual length of from */
58 #else
59     socklen_t fromlen;				/**< the actual length of from */
60 #endif
61 
62     int recvlen;					/**< the length of received data */
63 
64     struct timeval time_stamp;
65 } alc_rcv_container_t;
66 
67 /**
68  * List item for received packet.
69  * @struct alc_list_node
70  */
71 
72 typedef struct alc_list_node {
73     struct alc_list_node  *next; /**< next item in the list*/
74     void  *data;				/**< pointer to the stored data (alc_rcv_container) */
75 } alc_list_node_t;
76 
77 /**
78  * List for received packets.
79  * @struct alc_list
80  */
81 
82 typedef struct alc_list {
83     struct alc_list_node  *first_elem; /**< first item in the list */
84     struct alc_list_node  *last_elem;  /**< last item in the list */
85 
86 #ifdef _MSC_VER
87     RTL_CRITICAL_SECTION session_variables_semaphore; /**< used when the list is locked/unlocked */
88 #else
89     pthread_mutex_t session_variables_semaphore;      /**< used when the list is locked/unlocked */
90 #endif
91 
92 } alc_list_t;
93 
94 /**
95  * This function inserts the data to the end of the list.
96  *
97  * @param a_list the list
98  * @param a_data the data
99  *
100  */
101 
102 void push_back(alc_list_t *a_list, alc_rcv_container_t *a_data);
103 
104 /**
105  * This function inserts the data to the beginning of the list.
106  *
107  * @param a_list the list
108  * @param a_data the data
109  *
110  */
111 
112 void push_front(alc_list_t *a_list, alc_rcv_container_t *a_data);
113 
114 /**
115  * This function returns the data from the beginning of the list.
116  *
117  * @param a_list the list
118  *
119  * @return pointer to the data, NULL if the list is empty
120  *
121  */
122 
123 alc_rcv_container_t *pop_front(alc_list_t *a_list);
124 
125 /**
126  * This function checks if the list is empty.
127  *
128  * @param a_list the list
129  *
130  * @return 1 if the list is empty, 0 if not
131  *
132  */
133 
134 int is_empty(const alc_list_t *a_list);
135 
136 /**
137  * This function creates new list.
138  *
139  * @return pointer to the created list, NULL in error cases.
140  *
141  */
142 
143 alc_list_t* build_list(void);
144 
145 /**
146  * This function destroy the list.
147  *
148  * @param a_list the list
149  *
150  */
151 
152 void destroy_list(alc_list_t *a_list);
153 
154 #endif
155