1 /*******************************************************************************
2 * File : LudpReceiver.h
5 * Created : 2009-10-13 9:02:32
7 ******************************************************************************/
9 #ifndef __LUDPRECEIVER_INC_20091013_090232_HENRY__
10 #define __LUDPRECEIVER_INC_20091013_090232_HENRY__
13 /*******************************************************************************
14 * Desc : Includes Files
15 ******************************************************************************/
16 #include "utils/common.h"
17 #include "ludp/common.h"
21 /*******************************************************************************
22 * Desc : Macro Definations
23 ******************************************************************************/
26 ////////////////////////////////////////////////////////////////////////////////
29 #define LUDP_RECEIVER_ERR_FAILED (-1)
30 #define LUDP_RECEIVER_ERR_NOT_CREATED (-2)
31 #define LUDP_RECEIVER_ERR_ALREADY_CREATED (-3)
32 #define LUDP_RECEIVER_ERR_CANT_CREATE (-4)
34 ////////////////////////////////////////////////////////////////////////////////
37 #define LUDP_RECEIVER_MAX_RESEND_SLICE_SN_PER_SLICE 200
39 /*******************************************************************************
40 * Desc : Type Definations
41 ******************************************************************************/
43 ////////////////////////////////////////////////////////////////////////////////
44 // Struct of Receiver Package
46 typedef struct tagReceiverPackage
48 // Whether this package finished
51 // Timestamp of this package
54 // Slice pointer number
57 // Number of slices not received
60 // Array of slice pointers
63 // If Timeout reached (unTimeout == 0), unRetry--,
64 // don't retry to ask sender to resend if unRetry == 0;
66 // If unTimeout == 0 and unRetry != 0,
67 // ask sender to resend part of this package
73 ////////////////////////////////////////////////////////////////////////////////
75 typedef void (*OnLudpRecvFunc
) (void *pvParam
, ReceiverPackage
&zrpPkg
);
78 /*******************************************************************************
79 * Desc : Global Variables
80 ******************************************************************************/
86 /*******************************************************************************
88 ******************************************************************************/
94 /******************************************************************************
95 * Desc : Ludp Receiver
96 ******************************************************************************/
101 /******************************************************************************
102 * Desc : Constructor / Deconstructor
103 ******************************************************************************/
105 virtual ~LudpReceiver ();
109 /******************************************************************************
111 ******************************************************************************/
113 HLH_UDPSock
&zhuSock
,
115 OnLudpRecvFunc OnLudpRecv
,
116 void *pvOnLudpRecvParam
,
123 // Destroy this LudpReceiver
126 // Whether this instance created
131 /******************************************************************************
133 ******************************************************************************/
135 ////////////////////////////////////////////////////////////////////////////////
136 // Whether zhrTimestamp in current receive range
137 bool IsInRecvRange (HLH_RoundU32 zhrTimestamp
);
140 // Update timestamp range and package list if need according to zhrTimestamp
141 bool UpdateRecvRange (HLH_RoundU32 zhrTimestamp
);
143 // Clear package list in range (unPosLow ~ unPosHigh)
144 void ClearPkgListRange (UINT32 unPosLow
, UINT32 unPosHigh
);
146 ////////////////////////////////////////////////////////////////////////////////
147 // Process Slice received
148 int ProcessSlice (Slice
* pzsSlice
);
150 ////////////////////////////////////////////////////////////////////////////////
151 // Receive data from socket
152 static void OnReceived (
154 void *pvBuf
, UINT32 unLen
,
155 HLH_SockAddr
&zhsPeerAddr
);
158 ////////////////////////////////////////////////////////////////////////////////
159 // Send Request to sender to resend some slice of package (unTimestamp)
160 int SendRequest (UINT32 unTimestamp
);
162 // Check for timeout and Send request to sender to resend some slice
163 void CheckTimeout (HLH_Thread
&zhtTimeoutThread
);
165 ////////////////////////////////////////////////////////////////////////////////
166 // TimeoutThreadFunc:
167 // Check for timeout and Send request to sender to resend some slice
168 static void * TimeoutThreadFunc (HLH_Thread
&zhtTimeoutThread
, void *pvThis
);
173 /******************************************************************************
174 * Desc : Private Data
175 ******************************************************************************/
176 ////////////////////////////////////////////////////////////////////////////////
177 // Mutex of this instance
178 HLH_Mutex m_zhmMutex
;
180 // Whether this instance created
183 // Whether first package received
186 // Socket of ludp (shared with others)
187 HLH_UDPSock
* m_pzhuSock
;
189 // Base type of slices to process by this receiver
193 ////////////////////////////////////////////////////////////////////////////////
194 // Timestamp Range, initialed by the first slice received
195 HLH_RoundU32 m_zhrTimestampHigh
;
198 HLH_Time m_zhtTimeTick
;
200 // Default timeout value
201 UINT32 m_unMaxTimeout
;
207 ////////////////////////////////////////////////////////////////////////////////
208 // Ring Buffer of Package List Pointer
209 ReceiverPackage
* m_pzrPkgList
;
211 // Number of Ring Buffer Pointer
214 // Current Positions of Ring Buffer
218 ////////////////////////////////////////////////////////////////////////////////
220 HLH_Thread m_zhtTimeoutThread
;
222 // Callback function called when finish receviing a package
223 OnLudpRecvFunc m_zolOnLudpRecv
;
225 // Parameter to m_zolOnLudpRecv ()
226 void *m_pvOnLudpRecvParam
;
232 #endif /* __LUDPRECEIVER_INC_20091013_090232_HENRY__ */