1 /* |
1 /* |
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
63 // --------------------------------------------------------------------------- |
63 // --------------------------------------------------------------------------- |
64 // |
64 // |
65 CReceiver::CReceiver( RSocket& aSocket, |
65 CReceiver::CReceiver( RSocket& aSocket, |
66 MReceiverCallback& aCallback, |
66 MReceiverCallback& aCallback, |
67 MIkeDebug& aDebug ) |
67 MIkeDebug& aDebug ) |
68 : CActive( EPriorityStandard ), |
68 : CTimer( EPriorityStandard ), |
69 iState( EIdle ), |
69 iState( EIdle ), |
70 iMsgPtr( 0, 0, 0 ), |
70 iMsgPtr( 0, 0, 0 ), |
71 iSocket( aSocket ), |
71 iSocket( aSocket ), |
72 iCallback( aCallback ), |
72 iCallback( aCallback ), |
73 iDebug( aDebug ) |
73 iDebug( aDebug ) |
80 // --------------------------------------------------------------------------- |
80 // --------------------------------------------------------------------------- |
81 // |
81 // |
82 void CReceiver::ConstructL() |
82 void CReceiver::ConstructL() |
83 { |
83 { |
84 DEBUG_LOG( _L("CReceiver::ConstructL") ); |
84 DEBUG_LOG( _L("CReceiver::ConstructL") ); |
|
85 CTimer::ConstructL(); |
85 } |
86 } |
86 |
87 |
87 // --------------------------------------------------------------------------- |
88 // --------------------------------------------------------------------------- |
88 // Sets IKE major version. |
89 // Sets IKE major version. |
89 // --------------------------------------------------------------------------- |
90 // --------------------------------------------------------------------------- |
242 |
243 |
243 // --------------------------------------------------------------------------- |
244 // --------------------------------------------------------------------------- |
244 // Handles error in receiving. |
245 // Handles error in receiving. |
245 // --------------------------------------------------------------------------- |
246 // --------------------------------------------------------------------------- |
246 // |
247 // |
247 void CReceiver::HandleError( const TInt aStatus ) |
248 void CReceiver::HandleError( const TInt aStatus, |
248 { |
249 const TBool aDelayNeeded ) |
249 DEBUG_LOG1( _L("CReceiver::HandleError, aStatus=%d"), aStatus ); |
250 { |
|
251 DEBUG_LOG3( _L("CReceiver::HandleError, aStatus=%d, error count=%d, delay needed=%d"), |
|
252 aStatus, iErrorCount, aDelayNeeded ); |
250 |
253 |
251 delete iMsg; |
254 delete iMsg; |
252 iMsg = NULL; |
255 iMsg = NULL; |
253 iMsgPtr.Set( 0, 0, 0 ); |
256 iMsgPtr.Set( 0, 0, 0 ); |
254 iState = EIdle; |
257 |
|
258 const TInt KMaxReceiverErrorCount( 20 ); |
255 |
259 |
256 if ( aStatus == KErrDied || |
260 if ( aStatus == KErrDied || |
257 aStatus == KErrServerTerminated || |
261 aStatus == KErrServerTerminated || |
258 aStatus == KErrNoMemory ) |
262 aStatus == KErrNoMemory || |
259 { |
263 iErrorCount >= KMaxReceiverErrorCount ) |
260 // Fatal error. Notify client. |
264 { |
|
265 // Fatal error or maximum error count reached. Notify client. |
|
266 iState = EIdle; |
261 iCallback.ReceiveError( aStatus ); |
267 iCallback.ReceiveError( aStatus ); |
262 } |
268 } |
|
269 else if ( aDelayNeeded ) |
|
270 { |
|
271 // Restart receiving after delay. |
|
272 iState = EWaitingAfterSocketError; |
|
273 const TInt KDelayIntervalSocketError( 1000000 ); // 1s |
|
274 After( iErrorCount*KDelayIntervalSocketError ); |
|
275 } |
263 else |
276 else |
264 { |
277 { |
265 // Error is not fatal. Restart receiving |
278 // Receiving can be continued without delay. |
|
279 iState = EIdle; |
266 Receive(); |
280 Receive(); |
267 } |
281 } |
268 } |
282 } |
269 |
283 |
270 // --------------------------------------------------------------------------- |
284 // --------------------------------------------------------------------------- |
306 // --------------------------------------------------------------------------- |
320 // --------------------------------------------------------------------------- |
307 // |
321 // |
308 void CReceiver::RunL() |
322 void CReceiver::RunL() |
309 { |
323 { |
310 IKESOCKET_ASSERT( iState == EWaitingData || |
324 IKESOCKET_ASSERT( iState == EWaitingData || |
311 iState == EReceiving ); |
325 iState == EReceiving || |
|
326 iState == EWaitingAfterSocketError ); |
312 DEBUG_LOG2( _L("CReceiver::RunL, iState=%d, iStatus=%d"), |
327 DEBUG_LOG2( _L("CReceiver::RunL, iState=%d, iStatus=%d"), |
313 iState, iStatus.Int() ); |
328 iState, iStatus.Int() ); |
314 |
329 |
315 if ( iStatus.Int() ) |
330 if ( iStatus.Int() ) |
316 { |
331 { |
317 HandleError( iStatus.Int() ); |
332 HandleError( iStatus.Int(), ETrue ); |
|
333 iErrorCount++; |
318 return; |
334 return; |
319 } |
335 } |
320 |
336 |
321 switch ( iState ) |
337 switch ( iState ) |
322 { |
338 { |
341 // --------------------------------------------------------------------------- |
364 // --------------------------------------------------------------------------- |
342 // |
365 // |
343 void CReceiver::DoCancel() |
366 void CReceiver::DoCancel() |
344 { |
367 { |
345 IKESOCKET_ASSERT( iState == EWaitingData || |
368 IKESOCKET_ASSERT( iState == EWaitingData || |
346 iState == EReceiving ); |
369 iState == EReceiving || |
|
370 iState == EWaitingAfterSocketError ); |
347 DEBUG_LOG1( _L("CReceiver::DoCancel, iState=%d"), |
371 DEBUG_LOG1( _L("CReceiver::DoCancel, iState=%d"), |
348 iState ); |
372 iState ); |
349 |
373 |
|
374 iErrorCount = 0; |
|
375 |
350 switch ( iState ) |
376 switch ( iState ) |
351 { |
377 { |
352 case EWaitingData: |
378 case EWaitingData: |
353 { |
379 { |
354 iSocket.CancelIoctl(); |
380 iSocket.CancelIoctl(); |