53 iConnection(aConnection), |
59 iConnection(aConnection), |
54 iReceiveDataSink(NULL), |
60 iReceiveDataSink(NULL), |
55 iSendDataSource(NULL), |
61 iSendDataSource(NULL), |
56 iCurrentChunkData(NULL,0,0) |
62 iCurrentChunkData(NULL,0,0) |
57 { |
63 { |
|
64 OstTraceFunctionEntry0( CPTPIPSOCKETHANDLERBASE_CPTPIPSOCKETHANDLERBASE_ENTRY ); |
58 CActiveScheduler::Add(this); |
65 CActiveScheduler::Add(this); |
|
66 OstTraceFunctionExit0( CPTPIPSOCKETHANDLERBASE_CPTPIPSOCKETHANDLERBASE_EXIT ); |
59 } |
67 } |
60 |
68 |
61 |
69 |
62 |
70 |
63 /** |
71 /** |
64 Second phase constructor. |
72 Second phase constructor. |
65 */ |
73 */ |
66 #ifdef __FLOG_ACTIVE |
|
67 void CPTPIPSocketHandlerBase::ConstructL(const TDesC8& aComponentName) |
|
68 #else |
|
69 void CPTPIPSocketHandlerBase::ConstructL() |
74 void CPTPIPSocketHandlerBase::ConstructL() |
70 #endif |
|
71 { |
75 { |
72 __FLOG_OPEN(KMTPSubsystem, aComponentName); |
76 OstTraceFunctionEntry0( CPTPIPSOCKETHANDLERBASE_CONSTRUCTL_ENTRY ); |
73 __FLOG(_L8("CSocketHandler::ConstructL - Entry")); |
|
74 iPacketSizeMax = KMaxPacketSixe; |
77 iPacketSizeMax = KMaxPacketSixe; |
75 iPacketBuffer.ReAllocL(iPacketSizeMax); |
78 iPacketBuffer.ReAllocL(iPacketSizeMax); |
76 iPTPIPDataHeader = CPTPIPDataContainer::NewL(); |
79 iPTPIPDataHeader = CPTPIPDataContainer::NewL(); |
77 __FLOG(_L8("CSocketHandler::ConstructL - Exit")); |
80 OstTraceFunctionExit0( CPTPIPSOCKETHANDLERBASE_CONSTRUCTL_EXIT ); |
78 } |
81 } |
79 |
82 |
80 /** |
83 /** |
81 Destructor |
84 Destructor |
82 */ |
85 */ |
83 CPTPIPSocketHandlerBase::~CPTPIPSocketHandlerBase() |
86 CPTPIPSocketHandlerBase::~CPTPIPSocketHandlerBase() |
84 { |
87 { |
85 __FLOG(_L8("CSocketHandler::~CSocketHandler - Entry")); |
88 OstTraceFunctionEntry0( DUP1_CPTPIPSOCKETHANDLERBASE_CPTPIPSOCKETHANDLERBASE_ENTRY ); |
86 Cancel(); |
89 Cancel(); |
87 iPacketBuffer.Close(); |
90 iPacketBuffer.Close(); |
88 iSocket.Close(); |
91 iSocket.Close(); |
89 delete iPTPIPDataHeader; |
92 delete iPTPIPDataHeader; |
90 __FLOG(_L8("CSocketHandler::~CSocketHandler - Exit")); |
93 OstTraceFunctionExit0( DUP1_CPTPIPSOCKETHANDLERBASE_CPTPIPSOCKETHANDLERBASE_EXIT ); |
91 __FLOG_CLOSE; |
|
92 } |
94 } |
93 |
95 |
94 |
96 |
95 // |
97 // |
96 // CActive Functions |
98 // CActive Functions |
99 /** |
101 /** |
100 This will be called after every chunk is sent or received over the socket. |
102 This will be called after every chunk is sent or received over the socket. |
101 */ |
103 */ |
102 void CPTPIPSocketHandlerBase::RunL() |
104 void CPTPIPSocketHandlerBase::RunL() |
103 { |
105 { |
104 __FLOG(_L8("RunL - Entry")); |
106 OstTraceFunctionEntry0( CPTPIPSOCKETHANDLERBASE_RUNL_ENTRY ); |
105 __FLOG_VA((_L8("Current State is 0x%08X, and status is %d"), iState, iStatus.Int())); |
107 OstTraceExt2( TRACE_NORMAL, CPTPIPSOCKETHANDLERBASE_RUNL, "Current State is 0x%08X, and status is %d", |
|
108 iState, iStatus.Int()); |
|
109 |
106 |
110 |
107 switch ( DataStreamDirection() ) |
111 switch ( DataStreamDirection() ) |
108 { |
112 { |
109 case EReceivingState: |
113 case EReceivingState: |
110 |
114 |
111 __FLOG_VA((_L8("Receive data completion status = %d"), iStatus.Int())); |
115 OstTrace1( TRACE_NORMAL, DUP1_CPTPIPSOCKETHANDLERBASE_RUNL, "Receive data completion status = %d", |
|
116 iStatus.Int()); |
|
117 |
112 if (iState == EReceiveFastInProgress) |
118 if (iState == EReceiveFastInProgress) |
113 { |
119 { |
114 InitiateFirstChunkReceiveL(); |
120 InitiateFirstChunkReceiveL(); |
115 } |
121 } |
116 |
122 |
117 else if (iStatus != KErrNone) |
123 else if (iStatus != KErrNone) |
118 { |
124 { |
119 // Abnormal completion. |
125 // Abnormal completion. |
120 __FLOG_VA((_L8("PTPIP Error: Receive data completed with error = %d"), iStatus.Int())); |
126 OstTrace1( TRACE_NORMAL, DUP2_CPTPIPSOCKETHANDLERBASE_RUNL, "PTPIP Error: Receive data completed with error = %d", |
|
127 iStatus.Int()); |
|
128 |
121 SetState(EReceiveComplete); |
129 SetState(EReceiveComplete); |
122 } |
130 } |
123 else if (iState != EReceiveComplete) |
131 else if (iState != EReceiveComplete) |
124 { |
132 { |
125 // Update the chunk data length. We use the iReceiveData variable with the socket |
133 // Update the chunk data length. We use the iReceiveData variable with the socket |
218 } |
232 } |
219 break; |
233 break; |
220 |
234 |
221 default: |
235 default: |
222 |
236 |
223 __FLOG_VA((_L8("PTPIP ERROR: Invalid state of the sockethandler: RunL should not be called with 0x%08X state"), iState)); |
237 OstTrace1( TRACE_NORMAL, DUP6_CPTPIPSOCKETHANDLERBASE_RUNL, "PTPIP ERROR: Invalid state of the sockethandler: RunL should not be called with 0x%08X state", |
|
238 iState); |
|
239 |
224 Panic(EPTPIPBadState); |
240 Panic(EPTPIPBadState); |
225 break; |
241 break; |
226 |
242 |
227 }// switch |
243 }// switch |
228 |
244 OstTrace1( TRACE_NORMAL, DUP7_CPTPIPSOCKETHANDLERBASE_RUNL, "IsActive = %d", |
229 __FLOG_VA((_L8("IsActive = %d"), IsActive())); |
245 IsActive()); |
230 __FLOG(_L8("RunL - Exit")); |
246 |
|
247 OstTraceFunctionExit0( CPTPIPSOCKETHANDLERBASE_RUNL_EXIT ); |
231 } |
248 } |
232 |
249 |
233 /** |
250 /** |
234 Tell the Asynchronous Service provider to cancel all outstanding operations. |
251 Tell the Asynchronous Service provider to cancel all outstanding operations. |
235 */ |
252 */ |
236 void CPTPIPSocketHandlerBase::DoCancel() |
253 void CPTPIPSocketHandlerBase::DoCancel() |
237 { |
254 { |
238 __FLOG(_L8("DoCancel - Entry")); |
255 OstTraceFunctionEntry0( CPTPIPSOCKETHANDLERBASE_DOCANCEL_ENTRY ); |
239 switch (iState & EStateDirection) |
256 switch (iState & EStateDirection) |
240 { |
257 { |
241 case EReceivingState: |
258 case EReceivingState: |
242 __FLOG(_L8("Cancelling receive on the socket")); |
259 OstTrace0( TRACE_NORMAL, CPTPIPSOCKETHANDLERBASE_DOCANCEL, "Cancelling receive on the socket" ); |
|
260 |
243 iSocket.CancelRecv(); |
261 iSocket.CancelRecv(); |
244 ResetReceiveDataStream(); |
262 ResetReceiveDataStream(); |
245 break; |
263 break; |
246 |
264 |
247 case ESendingState: |
265 case ESendingState: |
248 __FLOG(_L8("Cancelling send on the socket")); |
266 OstTrace0( TRACE_NORMAL, DUP1_CPTPIPSOCKETHANDLERBASE_DOCANCEL, "Cancelling send on the socket" ); |
|
267 |
249 iSocket.CancelSend(); |
268 iSocket.CancelSend(); |
250 ResetSendDataStream(); |
269 ResetSendDataStream(); |
251 break; |
270 break; |
252 |
271 |
253 case ESendDataState: |
272 case ESendDataState: |
254 __FLOG(_L8("Cancelling send on the socket")); |
273 OstTrace0( TRACE_NORMAL, DUP2_CPTPIPSOCKETHANDLERBASE_DOCANCEL, "Cancelling send on the socket" ); |
|
274 |
255 iSocket.CancelSend(); |
275 iSocket.CancelSend(); |
256 ResetSendDataStream(); |
276 ResetSendDataStream(); |
257 break; |
277 break; |
258 |
278 |
259 default: |
279 default: |
260 break; |
280 break; |
261 } |
281 } |
262 __FLOG(_L8("DoCancel - Exit")); |
282 OstTraceFunctionExit0( CPTPIPSOCKETHANDLERBASE_DOCANCEL_EXIT ); |
263 } |
283 } |
264 |
284 |
265 /** |
285 /** |
266 This is invoked when a panic occurs during RunL. |
286 This is invoked when a panic occurs during RunL. |
267 To handle this , all operations are cancelled, and if we were processing |
287 To handle this , all operations are cancelled, and if we were processing |
268 a send or recv operation, we complete it with the error code. |
288 a send or recv operation, we complete it with the error code. |
269 @param - The error code with which RunL left |
289 @param - The error code with which RunL left |
270 */ |
290 */ |
271 TInt CPTPIPSocketHandlerBase::RunError(TInt aError) |
291 TInt CPTPIPSocketHandlerBase::RunError(TInt aError) |
272 { |
292 { |
273 __FLOG(_L8("RunError - Entry")); |
293 OstTraceFunctionEntry0( CPTPIPSOCKETHANDLERBASE_RUNERROR_ENTRY ); |
274 __FLOG_VA((_L8("Error reported is %d and state is 0x%08X, and status is %d"), aError, iState, iStatus.Int())); |
294 OstTraceExt3( TRACE_NORMAL, CPTPIPSOCKETHANDLERBASE_RUNERROR, "Error reported is %d and state is 0x%08X, and status is %d", |
|
295 aError, iState, iStatus.Int()); |
|
296 |
275 |
297 |
276 // Cancel any outstanding request. |
298 // Cancel any outstanding request. |
277 Cancel(); |
299 Cancel(); |
278 |
300 |
279 // Notify the protocol layer of the error. |
301 // Notify the protocol layer of the error. |
280 TInt32 streamDirection = DataStreamDirection(); |
302 TInt32 streamDirection = DataStreamDirection(); |
281 if (streamDirection == EReceivingState) |
303 if (streamDirection == EReceivingState) |
282 { |
304 { |
283 __FLOG(_L8("Error in EReceivingState")); |
305 OstTrace0( TRACE_NORMAL, DUP1_CPTPIPSOCKETHANDLERBASE_RUNERROR, "Error in EReceivingState" ); |
|
306 |
284 // Notify the connection and reset the receive data stream. |
307 // Notify the connection and reset the receive data stream. |
285 MMTPType& data(*iReceiveDataSink); |
308 MMTPType& data(*iReceiveDataSink); |
286 ResetReceiveDataStream(); |
309 ResetReceiveDataStream(); |
287 TRAPD(err, ReceiveDataCompleteL(aError, data)); |
310 TRAPD(err, ReceiveDataCompleteL(aError, data)); |
288 UNUSED_VAR(err); |
311 UNUSED_VAR(err); |
289 } |
312 } |
290 else if (streamDirection == ESendingState || (streamDirection == ESendDataState)) |
313 else if (streamDirection == ESendingState || (streamDirection == ESendDataState)) |
291 { |
314 { |
292 __FLOG(_L8("Error in ESendingState")); |
315 OstTrace0( TRACE_NORMAL, DUP2_CPTPIPSOCKETHANDLERBASE_RUNERROR, "Error in ESendingState" ); |
|
316 |
293 // Notify the connection and reset the send data stream. |
317 // Notify the connection and reset the send data stream. |
294 const MMTPType& data(*iSendDataSource); |
318 const MMTPType& data(*iSendDataSource); |
295 ResetSendDataStream(); |
319 ResetSendDataStream(); |
296 TRAPD(err, SendDataCompleteL(aError, data)); |
320 TRAPD(err, SendDataCompleteL(aError, data)); |
297 UNUSED_VAR(err); |
321 UNUSED_VAR(err); |
319 in case the data in R to I phase has to be split into multiple PTPIP data packets |
343 in case the data in R to I phase has to be split into multiple PTPIP data packets |
320 In such a case the PTPIP Data packet header needs to be created which contains the tran id. |
344 In such a case the PTPIP Data packet header needs to be created which contains the tran id. |
321 */ |
345 */ |
322 void CPTPIPSocketHandlerBase::SendDataL(const MMTPType& aData, TUint32 aTransactionId ) |
346 void CPTPIPSocketHandlerBase::SendDataL(const MMTPType& aData, TUint32 aTransactionId ) |
323 { |
347 { |
324 __FLOG(_L8("SendDataL - Entry")); |
348 OstTraceFunctionEntry0( CPTPIPSOCKETHANDLERBASE_SENDDATAL_ENTRY ); |
325 iSendDataSource = &aData; |
349 iSendDataSource = &aData; |
326 TUint64 size = iSendDataSource->Size(); |
350 TUint64 size = iSendDataSource->Size(); |
327 __FLOG_VA((_L8("Size of total data to be sent = %ld bytes"), size)); |
351 OstTrace1( TRACE_NORMAL, CPTPIPSOCKETHANDLERBASE_SENDDATAL, "Size of total data to be sent = %ld bytes", |
|
352 size); |
|
353 |
328 |
354 |
329 // if the data is less than KMaxPTPIPPacketSize then it can be sent in a shot, |
355 // if the data is less than KMaxPTPIPPacketSize then it can be sent in a shot, |
330 // Currently the ptp ip packet has the end data packet already, so it can be sent directly. |
356 // Currently the ptp ip packet has the end data packet already, so it can be sent directly. |
331 if ( size < KMaxPTPIPPacketSize) |
357 if ( size < KMaxPTPIPPacketSize) |
332 { |
358 { |
333 __FLOG(_L8("Size of data is less than KMaxPTPIPPacketSize, sending as one ptpip packet.")); |
359 OstTrace0( TRACE_NORMAL, DUP2_CPTPIPSOCKETHANDLERBASE_SENDDATAL, "Size of data is less than KMaxPTPIPPacketSize, sending as one ptpip packet." ); |
|
360 |
334 SetState(ESendInitialising); |
361 SetState(ESendInitialising); |
335 ProcessSendDataL(); |
362 ProcessSendDataL(); |
336 } |
363 } |
337 |
364 |
338 // if the data is greater than KMaxPTPIPPacketSize then it needs to be split into |
365 // if the data is greater than KMaxPTPIPPacketSize then it needs to be split into |
339 // multiple packets. The PTPIP header will be locally created , and sent |
366 // multiple packets. The PTPIP header will be locally created , and sent |
340 // and then one chunk will be sent as one PTPIP packet. |
367 // and then one chunk will be sent as one PTPIP packet. |
341 else |
368 else |
342 { |
369 { |
343 __FLOG(_L8("Size of data is more than KMaxPTPIPPacketSize, sending as multiple ptpip packets.")); |
370 OstTrace0( TRACE_NORMAL, DUP1_CPTPIPSOCKETHANDLERBASE_SENDDATAL, "Size of data is more than KMaxPTPIPPacketSize, sending as multiple ptpip packets." ); |
|
371 |
344 iPTPIPDataHeader->SetUint32L(CPTPIPDataContainer::ETransactionId, aTransactionId); |
372 iPTPIPDataHeader->SetUint32L(CPTPIPDataContainer::ETransactionId, aTransactionId); |
345 iPTPIPDataHeader->SetPayloadL(NULL); |
373 iPTPIPDataHeader->SetPayloadL(NULL); |
346 |
374 |
347 // We can ignore this header, since we create our own while sending each packet. |
375 // We can ignore this header, since we create our own while sending each packet. |
348 iChunkStatus = iSendDataSource->FirstReadChunk(iSendChunkData); |
376 iChunkStatus = iSendDataSource->FirstReadChunk(iSendChunkData); |
349 |
377 |
350 SetState(ESendingDataHeader); |
378 SetState(ESendingDataHeader); |
351 CreateAndSendDataPacketsL(); |
379 CreateAndSendDataPacketsL(); |
352 } |
380 } |
353 |
381 |
354 __FLOG(_L8("SendDataL - Exit")); |
382 OstTraceFunctionExit0( CPTPIPSOCKETHANDLERBASE_SENDDATAL_EXIT ); |
355 } |
383 } |
356 |
384 |
357 /** |
385 /** |
358 Using the same algo as the USB send, to buffer into a local buffer, and sending |
386 Using the same algo as the USB send, to buffer into a local buffer, and sending |
359 only when buffer exceeds the max socket send size, or all chunks have been buffered. |
387 only when buffer exceeds the max socket send size, or all chunks have been buffered. |
360 */ |
388 */ |
361 void CPTPIPSocketHandlerBase::ProcessSendDataL() |
389 void CPTPIPSocketHandlerBase::ProcessSendDataL() |
362 { |
390 { |
363 __FLOG(_L8("ProcessSendDataL - Entry")); |
391 OstTraceFunctionEntry0( CPTPIPSOCKETHANDLERBASE_PROCESSSENDDATAL_ENTRY ); |
364 |
392 |
365 iSendData.Set(KNullDesC8); |
393 iSendData.Set(KNullDesC8); |
366 |
394 |
367 TUint chunkAvailableLen(iSendChunkData.Length()); |
395 TUint chunkAvailableLen(iSendChunkData.Length()); |
368 if (!chunkAvailableLen) |
396 if (!chunkAvailableLen) |
369 { |
397 { |
370 // Fetch the next read data chunk. |
398 // Fetch the next read data chunk. |
371 switch (iState) |
399 switch (iState) |
372 { |
400 { |
373 case ESendInitialising: |
401 case ESendInitialising: |
374 __FLOG(_L8("Fetching first read data chunk")); |
402 OstTrace0( TRACE_NORMAL, CPTPIPSOCKETHANDLERBASE_PROCESSSENDDATAL, "Fetching first read data chunk" ); |
|
403 |
375 iChunkStatus = iSendDataSource->FirstReadChunk(iSendChunkData); |
404 iChunkStatus = iSendDataSource->FirstReadChunk(iSendChunkData); |
376 iPacketBuffer.Zero(); |
405 iPacketBuffer.Zero(); |
377 break; |
406 break; |
378 |
407 |
379 case ESendInProgress: |
408 case ESendInProgress: |
380 __FLOG(_L8("Fetching next read data chunk")); |
409 OstTrace0( TRACE_NORMAL, DUP1_CPTPIPSOCKETHANDLERBASE_PROCESSSENDDATAL, "Fetching next read data chunk" ); |
|
410 |
381 iChunkStatus = iSendDataSource->NextReadChunk(iSendChunkData); |
411 iChunkStatus = iSendDataSource->NextReadChunk(iSendChunkData); |
382 break; |
412 break; |
383 |
413 |
384 case ESendCompleting: |
414 case ESendCompleting: |
385 break; |
415 break; |
386 |
416 |
387 case EIdle: |
417 case EIdle: |
388 default: |
418 default: |
389 __FLOG(_L8("Invalid send data stream state")); |
419 OstTrace0( TRACE_NORMAL, DUP2_CPTPIPSOCKETHANDLERBASE_PROCESSSENDDATAL, "Invalid send data stream state" ); |
|
420 |
390 Panic(EPTPIPBadState); |
421 Panic(EPTPIPBadState); |
391 break; |
422 break; |
392 } |
423 } |
393 |
424 |
394 // Fetch the new chunk data size available. |
425 // Fetch the new chunk data size available. |
424 SetState(ESendCompleting); |
455 SetState(ESendCompleting); |
425 } |
456 } |
426 } |
457 } |
427 break; |
458 break; |
428 default: |
459 default: |
429 User::Leave(iChunkStatus); |
460 LEAVEIFERROR(iChunkStatus, |
|
461 OstTrace1( TRACE_ERROR, DUP17_CPTPIPSOCKETHANDLERBASE_PROCESSSENDDATAL, "iChunkStatus is %d", iChunkStatus )); |
|
462 |
430 break; |
463 break; |
431 } |
464 } |
432 } |
465 } |
433 __FLOG_VA((_L8("Chunk status = %d"), iChunkStatus)); |
466 OstTrace1( TRACE_NORMAL, DUP3_CPTPIPSOCKETHANDLERBASE_PROCESSSENDDATAL, "Chunk status = %d", |
|
467 iChunkStatus); |
|
468 |
434 |
469 |
435 // Process the buffered residual and/or available chunk data. |
470 // Process the buffered residual and/or available chunk data. |
436 TUint bufferedLen(iPacketBuffer.Length()); |
471 TUint bufferedLen(iPacketBuffer.Length()); |
437 TUint chunkIntegralLen((chunkAvailableLen / iPacketSizeMax) * iPacketSizeMax); |
472 TUint chunkIntegralLen((chunkAvailableLen / iPacketSizeMax) * iPacketSizeMax); |
438 TUint chunkResidualLen(chunkAvailableLen % iPacketSizeMax); |
473 TUint chunkResidualLen(chunkAvailableLen % iPacketSizeMax); |
439 __FLOG_VA((_L8("Buffered residual data = %d bytes"), bufferedLen)); |
474 OstTrace1( TRACE_NORMAL, DUP4_CPTPIPSOCKETHANDLERBASE_PROCESSSENDDATAL, "Buffered residual data = %d bytes", |
440 __FLOG_VA((_L8("Chunk data available = %d bytes"), chunkAvailableLen)); |
475 bufferedLen); |
441 __FLOG_VA((_L8("Chunk data packet integral portion = %d bytes"), chunkIntegralLen)); |
476 OstTrace1( TRACE_NORMAL, DUP5_CPTPIPSOCKETHANDLERBASE_PROCESSSENDDATAL, "Chunk data available = %d bytes", |
442 __FLOG_VA((_L8("Chunk data packet residual portion = %d bytes"), chunkResidualLen)); |
477 chunkAvailableLen); |
|
478 OstTrace1( TRACE_NORMAL, DUP6_CPTPIPSOCKETHANDLERBASE_PROCESSSENDDATAL, "Chunk data packet integral portion = %d bytes", |
|
479 chunkIntegralLen); |
|
480 OstTrace1( TRACE_NORMAL, DUP7_CPTPIPSOCKETHANDLERBASE_PROCESSSENDDATAL, "Chunk data packet residual portion = %d bytes", |
|
481 chunkResidualLen); |
443 |
482 |
444 if (bufferedLen) |
483 if (bufferedLen) |
445 { |
484 { |
446 // Data is buffered in the packet buffer. Fill the available packet buffer space. |
485 // Data is buffered in the packet buffer. Fill the available packet buffer space. |
447 if (chunkAvailableLen) |
486 if (chunkAvailableLen) |
511 |
556 |
512 // Send the available data or reschedule to process the next chunk. |
557 // Send the available data or reschedule to process the next chunk. |
513 TUint sendBytes(iSendData.Length()); |
558 TUint sendBytes(iSendData.Length()); |
514 if (sendBytes) |
559 if (sendBytes) |
515 { |
560 { |
516 __FLOG_VA((_L8("Send data length = %d bytes"), iSendData.Length())); |
561 OstTrace1( TRACE_NORMAL, DUP16_CPTPIPSOCKETHANDLERBASE_PROCESSSENDDATAL, "Send data length = %d bytes", |
517 #ifdef MTP_DEBUG_FLOG_HEX_DUMP |
562 iSendData.Length()); |
518 __FLOG_HEXDUMP((iSendData, _L8("Sending data on socket "))); |
563 |
|
564 OstTrace1( TRACE_NORMAL, DUP11_CPTPIPSOCKETHANDLERBASE_PROCESSSENDDATAL, "Send data length = %d bytes", |
|
565 iSendData.Length()); |
|
566 |
|
567 #ifdef MTP_DEBUG_OST_HEX_DUMP |
|
568 OstTrace0( TRACE_NORMAL, DUP12_CPTPIPSOCKETHANDLERBASE_PROCESSSENDDATAL, "Sending data on socket " ); |
|
569 OstTraceData( TRACE_DUMP, DUP13_CPTPIPSOCKETHANDLERBASE_PROCESSSENDDATAL, |
|
570 "%x", iSendData.Ptr(), iSendData.Size()); |
519 #endif |
571 #endif |
|
572 |
520 iSocket.Send(iSendData, 0, iStatus); |
573 iSocket.Send(iSendData, 0, iStatus); |
521 SetActive(); |
574 SetActive(); |
522 __FLOG(_L8("Request issued")); |
575 OstTrace0( TRACE_NORMAL, DUP14_CPTPIPSOCKETHANDLERBASE_PROCESSSENDDATAL, "Request issued" ); |
|
576 |
523 } |
577 } |
524 else if (iState != ESendComplete) |
578 else if (iState != ESendComplete) |
525 { |
579 { |
526 iStatus = KRequestPending; |
580 iStatus = KRequestPending; |
527 CompleteSelf(KErrNone); |
581 CompleteSelf(KErrNone); |
528 } |
582 } |
529 |
583 |
530 __FLOG_VA((_L8("CSocketHandler state on exit = 0x%08X"), iState)); |
584 OstTrace1( TRACE_NORMAL, DUP15_CPTPIPSOCKETHANDLERBASE_PROCESSSENDDATAL, "CSocketHandler state on exit = 0x%08X", iState ); |
531 __FLOG(_L8("ProcessSendDataL - Exit")); |
585 |
|
586 OstTraceFunctionExit0( CPTPIPSOCKETHANDLERBASE_PROCESSSENDDATAL_EXIT ); |
532 } |
587 } |
533 |
588 |
534 |
589 |
535 |
590 |
536 /** |
591 /** |
540 in case this is the last chunk, then the data header will have the last data |
595 in case this is the last chunk, then the data header will have the last data |
541 */ |
596 */ |
542 |
597 |
543 void CPTPIPSocketHandlerBase::CreateAndSendDataPacketsL() |
598 void CPTPIPSocketHandlerBase::CreateAndSendDataPacketsL() |
544 { |
599 { |
545 __FLOG(_L8("CreateAndSendDataPacketsL - Entry")); |
600 OstTraceFunctionEntry0( CPTPIPSOCKETHANDLERBASE_CREATEANDSENDDATAPACKETSL_ENTRY ); |
546 |
601 |
547 // Create the data header and prepare to send it. |
602 // Create the data header and prepare to send it. |
548 if (iState == ESendingDataHeader) |
603 if (iState == ESendingDataHeader) |
549 { |
604 { |
550 // if we've received a Cancel, then don't send further packets and return to the connection. |
605 // if we've received a Cancel, then don't send further packets and return to the connection. |
551 if (iCancelReceived) |
606 if (iCancelReceived) |
552 { |
607 { |
553 iState = ESendDataCancelled; |
608 iState = ESendDataCancelled; |
554 CompleteSelf(KErrNone); |
609 CompleteSelf(KErrNone); |
555 __FLOG(_L8("Sending the PTPIP data ")); |
610 OstTrace0( TRACE_NORMAL, CPTPIPSOCKETHANDLERBASE_CREATEANDSENDDATAPACKETSL, "Sending the PTPIP data " ); |
|
611 |
|
612 OstTraceFunctionExit0( CPTPIPSOCKETHANDLERBASE_CREATEANDSENDDATAPACKETSL_EXIT ); |
556 return; |
613 return; |
557 } |
614 } |
558 else |
615 else |
559 { |
616 { |
560 iChunkStatus = iSendDataSource->NextReadChunk(iSendChunkData); |
617 iChunkStatus = iSendDataSource->NextReadChunk(iSendChunkData); |
561 TInt32 size = iPTPIPDataHeader->Size() + iSendChunkData.Size(); |
618 TInt32 size = iPTPIPDataHeader->Size() + iSendChunkData.Size(); |
562 iPTPIPDataHeader->SetUint32L(CPTPIPDataContainer::EPacketLength, size); |
619 iPTPIPDataHeader->SetUint32L(CPTPIPDataContainer::EPacketLength, size); |
563 __FLOG_VA((_L8("Size of ptpip packet data to be sent = %d bytes"), size)); |
620 OstTrace1( TRACE_NORMAL, DUP1_CPTPIPSOCKETHANDLERBASE_CREATEANDSENDDATAPACKETSL, "Size of ptpip packet data to be sent = %d bytes", size ); |
|
621 |
564 |
622 |
565 switch (iChunkStatus) |
623 switch (iChunkStatus) |
566 { |
624 { |
567 case KErrNone: |
625 case KErrNone: |
568 iPTPIPDataHeader->SetUint32L(CPTPIPDataContainer::EPacketType, EPTPIPPacketTypeData); |
626 iPTPIPDataHeader->SetUint32L(CPTPIPDataContainer::EPacketType, EPTPIPPacketTypeData); |
584 |
645 |
585 // Set the iSendData to point to the actual data chunk. |
646 // Set the iSendData to point to the actual data chunk. |
586 else if (iState == ESendingDataPacket) |
647 else if (iState == ESendingDataPacket) |
587 { |
648 { |
588 iSendData.Set(iSendChunkData); |
649 iSendData.Set(iSendChunkData); |
589 __FLOG(_L8("Sending the PTPIP data ")); |
650 OstTrace0( TRACE_NORMAL, DUP3_CPTPIPSOCKETHANDLERBASE_CREATEANDSENDDATAPACKETSL, "Sending the PTPIP data " ); |
|
651 |
590 // if this is the last packet then set state. |
652 // if this is the last packet then set state. |
591 if (iChunkStatus == KMTPChunkSequenceCompletion) |
653 if (iChunkStatus == KMTPChunkSequenceCompletion) |
592 SetState(ESendDataPacketCompleting); |
654 SetState(ESendDataPacketCompleting); |
593 } |
655 } |
594 // We exited due to an error condition, |
656 // We exited due to an error condition, |
595 else |
657 else |
596 { |
658 { |
597 Panic(EPTPIPBadState); |
659 Panic(EPTPIPBadState); |
598 } |
660 } |
599 |
661 |
600 __FLOG_VA((_L8("Send data length = %d bytes"), iSendData.Length())); |
662 OstTrace1( TRACE_NORMAL, DUP4_CPTPIPSOCKETHANDLERBASE_CREATEANDSENDDATAPACKETSL, "Send data length = %d bytes", |
601 #ifdef MTP_DEBUG_FLOG_HEX_DUMP |
663 iSendData.Length()); |
602 __FLOG_HEXDUMP((iSendData, _L8("Sending data on socket "))); |
664 |
|
665 #ifdef MTP_DEBUG_OST_HEX_DUMP |
|
666 OstTrace0( TRACE_NORMAL, DUP5_CPTPIPSOCKETHANDLERBASE_CREATEANDSENDDATAPACKETSL, "Sending data on socket " ); |
|
667 OstTraceData( TRACE_DUMP, DUP6_CPTPIPSOCKETHANDLERBASE_CREATEANDSENDDATAPACKETSL, |
|
668 "%x", iSendData.Ptr(), iSendData.Size()); |
603 #endif |
669 #endif |
|
670 |
604 iSocket.Send(iSendData, 0, iStatus); |
671 iSocket.Send(iSendData, 0, iStatus); |
605 SetActive(); |
672 SetActive(); |
606 __FLOG(_L8("Request issued")); |
673 OstTrace0( TRACE_NORMAL, DUP7_CPTPIPSOCKETHANDLERBASE_CREATEANDSENDDATAPACKETSL, "Request issued" ); |
607 __FLOG(_L8("CreateAndSendDataPacketsL - Exit")); |
674 |
|
675 OstTraceFunctionExit0( DUP1_CPTPIPSOCKETHANDLERBASE_CREATEANDSENDDATAPACKETSL_EXIT ); |
608 } |
676 } |
609 |
677 |
610 |
678 |
611 |
679 |
612 /** |
680 /** |
616 @panic EPTPIPNotSupported In debug builds only, if the derived class has not fully |
684 @panic EPTPIPNotSupported In debug builds only, if the derived class has not fully |
617 implemented the send data path. |
685 implemented the send data path. |
618 */ |
686 */ |
619 void CPTPIPSocketHandlerBase::SendDataCompleteL(TInt /*aError*/, const MMTPType& /*aSource*/) |
687 void CPTPIPSocketHandlerBase::SendDataCompleteL(TInt /*aError*/, const MMTPType& /*aSource*/) |
620 { |
688 { |
621 __FLOG(_L8("CSocketHandler::SendDataCompleteL - Entry")); |
689 OstTraceFunctionEntry0( CPTPIPSOCKETHANDLERBASE_SENDDATACOMPLETEL_ENTRY ); |
622 __DEBUG_ONLY(Panic(EPTPIPNotSupported)); |
690 __DEBUG_ONLY(Panic(EPTPIPNotSupported)); |
623 __FLOG(_L8("CSocketHandler::SendDataCompleteL - Exit")); |
691 OstTraceFunctionExit0( CPTPIPSOCKETHANDLERBASE_SENDDATACOMPLETEL_EXIT ); |
624 } |
692 } |
625 |
693 |
626 /** |
694 /** |
627 Forces the completion of a transfer in progress. |
695 Forces the completion of a transfer in progress. |
628 |
696 |
629 @param aReason error code describing the reason for cancelling. |
697 @param aReason error code describing the reason for cancelling. |
630 @leave Any of the system wide error codes. |
698 @leave Any of the system wide error codes. |
631 */ |
699 */ |
632 void CPTPIPSocketHandlerBase::CancelSendL(TInt aReason) |
700 void CPTPIPSocketHandlerBase::CancelSendL(TInt aReason) |
633 { |
701 { |
634 __FLOG(_L8("CSocketHandler::CancelSendL - Entry")); |
702 OstTraceFunctionEntry0( CPTPIPSOCKETHANDLERBASE_CANCELSENDL_ENTRY ); |
635 |
703 |
636 if ( (DataStreamDirection() == ESendingState) || (DataStreamDirection() == ESendDataState)) |
704 if ( (DataStreamDirection() == ESendingState) || (DataStreamDirection() == ESendDataState)) |
637 { |
705 { |
638 __FLOG(_L8("Cancel in ESendingState")); |
706 OstTrace0( TRACE_NORMAL, CPTPIPSOCKETHANDLERBASE_CANCELSENDL, "Cancel in ESendingState" ); |
|
707 |
639 // Cancel any outstanding request. |
708 // Cancel any outstanding request. |
640 Cancel(); |
709 Cancel(); |
641 ResetSendDataStream(); |
710 ResetSendDataStream(); |
642 SendDataCompleteL(aReason, *iSendDataSource); |
711 SendDataCompleteL(aReason, *iSendDataSource); |
643 } |
712 } |
644 |
713 |
645 __FLOG(_L8("CSocketHandler::CancelSendL - Exit")); |
714 OstTraceFunctionExit0( CPTPIPSOCKETHANDLERBASE_CANCELSENDL_EXIT ); |
646 } |
715 } |
647 |
716 |
648 |
717 |
649 // |
718 // |
650 // Receive Data Functions |
719 // Receive Data Functions |
670 |
739 |
671 iReceiveDataSink = &aSink; |
740 iReceiveDataSink = &aSink; |
672 iReceiveDataCommit = iReceiveDataSink->CommitRequired(); |
741 iReceiveDataCommit = iReceiveDataSink->CommitRequired(); |
673 |
742 |
674 InitiateFirstChunkReceiveL(); |
743 InitiateFirstChunkReceiveL(); |
675 __FLOG(_L8("ReceiveDataL - Exit")); |
744 OstTraceFunctionExit0( CPTPIPSOCKETHANDLERBASE_RECEIVEDATAL_EXIT ); |
676 } |
745 } |
677 |
746 |
678 /** |
747 /** |
679 Reads the first chunk. Then validates what was read and adjusts the buffer accordingly. |
748 Reads the first chunk. Then validates what was read and adjusts the buffer accordingly. |
680 */ |
749 */ |
681 void CPTPIPSocketHandlerBase::InitiateFirstChunkReceiveL() |
750 void CPTPIPSocketHandlerBase::InitiateFirstChunkReceiveL() |
682 { |
751 { |
683 __FLOG(_L8("InitiateFirstChunkReceiveL - Entry")); |
752 OstTraceFunctionEntry0( CPTPIPSOCKETHANDLERBASE_INITIATEFIRSTCHUNKRECEIVEL_ENTRY ); |
684 |
753 |
685 // sink refers to the buffer from connection. |
754 // sink refers to the buffer from connection. |
686 // Now the ptr iReceiveChunkData is set to it first chunk. |
755 // Now the ptr iReceiveChunkData is set to it first chunk. |
687 iChunkStatus = iReceiveDataSink->FirstWriteChunk(iReceiveChunkData); |
756 iChunkStatus = iReceiveDataSink->FirstWriteChunk(iReceiveChunkData); |
688 |
757 |
689 // The first chunk is going to be read. |
758 // The first chunk is going to be read. |
690 iIsFirstChunk = ETrue; |
759 iIsFirstChunk = ETrue; |
691 __FLOG_VA((_L8("Receive chunk capacity = %d bytes, length = %d bytes"), iReceiveChunkData.MaxLength(), iReceiveChunkData.Length())); |
760 OstTraceExt2( TRACE_NORMAL, CPTPIPSOCKETHANDLERBASE_INITIATEFIRSTCHUNKRECEIVEL, "Receive chunk capacity = %d bytes, length = %d bytes", |
692 __FLOG_VA((_L8("Chunk status = %d"), iChunkStatus)); |
761 iReceiveChunkData.MaxLength(), iReceiveChunkData.Length()); |
|
762 |
|
763 OstTrace1( TRACE_NORMAL, DUP1_CPTPIPSOCKETHANDLERBASE_INITIATEFIRSTCHUNKRECEIVEL, "Chunk status = %d", |
|
764 iChunkStatus); |
|
765 |
693 |
766 |
694 iReceiveData.Set(iReceiveChunkData); |
767 iReceiveData.Set(iReceiveChunkData); |
695 |
768 |
696 // start the timer. |
769 // start the timer. |
697 |
770 |
698 // Make the async request to read on the socket and set ourselves active. |
771 // Make the async request to read on the socket and set ourselves active. |
699 // once data is read on the socket, the iStatus will be changed by the comms framework. |
772 // once data is read on the socket, the iStatus will be changed by the comms framework. |
700 iSocket.Recv(iReceiveData, 0, iStatus); |
773 iSocket.Recv(iReceiveData, 0, iStatus); |
701 #ifdef MTP_DEBUG_FLOG_HEX_DUMP |
774 |
702 __FLOG_HEXDUMP((iReceiveData, _L8("Received data on socket "))); |
775 #ifdef MTP_DEBUG_OST_HEX_DUMP |
|
776 OstTrace0( TRACE_NORMAL, DUP2_CPTPIPSOCKETHANDLERBASE_INITIATEFIRSTCHUNKRECEIVEL, "Received data on socket" ); |
|
777 OstTraceData( TRACE_DUMP, DUP3_CPTPIPSOCKETHANDLERBASE_INITIATEFIRSTCHUNKRECEIVEL, |
|
778 "%x", iReceiveData.Ptr(), iReceiveData.Size()); |
703 #endif |
779 #endif |
704 |
780 |
|
781 |
705 SetActive(); |
782 SetActive(); |
706 __FLOG(_L8("Request issued")); |
783 OstTrace0( TRACE_NORMAL, DUP4_CPTPIPSOCKETHANDLERBASE_INITIATEFIRSTCHUNKRECEIVEL, "Request issued" ); |
707 __FLOG(_L8("InitiateFirstChunkReceiveL - Exit")); |
784 |
|
785 OstTraceFunctionExit0( CPTPIPSOCKETHANDLERBASE_INITIATEFIRSTCHUNKRECEIVEL_EXIT ); |
708 } |
786 } |
709 |
787 |
710 /** |
788 /** |
711 The first chunk received will have the length of the data and the ptpip packet type. |
789 The first chunk received will have the length of the data and the ptpip packet type. |
712 Validate the ptp packet type, and set the correct packet type in the generic container. |
790 Validate the ptp packet type, and set the correct packet type in the generic container. |
713 Set the state to complete or read further depending on the size. |
791 Set the state to complete or read further depending on the size. |
714 */ |
792 */ |
715 void CPTPIPSocketHandlerBase::ProcessFirstReceivedChunkL() |
793 void CPTPIPSocketHandlerBase::ProcessFirstReceivedChunkL() |
716 { |
794 { |
717 __FLOG(_L8("ProcessFirstReceivedChunkL - Entry")); |
795 OstTraceFunctionEntry0( CPTPIPSOCKETHANDLERBASE_PROCESSFIRSTRECEIVEDCHUNKL_ENTRY ); |
718 iIsFirstChunk = EFalse; |
796 iIsFirstChunk = EFalse; |
719 // Reset the data counter, This will be filled in later in the ResumeReceiveDataStreamL. |
797 // Reset the data counter, This will be filled in later in the ResumeReceiveDataStreamL. |
720 iPTPPacketLengthReceived = 0; |
798 iPTPPacketLengthReceived = 0; |
721 iType = EPTPIPPacketTypeUndefined; |
799 iType = EPTPIPPacketTypeUndefined; |
722 |
800 |
739 { |
818 { |
740 SetState(EReceiveComplete); |
819 SetState(EReceiveComplete); |
741 } |
820 } |
742 |
821 |
743 if (iState == EReceiveComplete) |
822 if (iState == EReceiveComplete) |
744 { |
823 { |
745 #ifdef MTP_DEBUG_FLOG_HEX_DUMP |
824 #ifdef MTP_DEBUG_OST_HEX_DUMP |
746 __FLOG_HEXDUMP((iReceiveChunkData, _L8("Received data "))); |
825 OstTrace0( TRACE_NORMAL, DUP1_CPTPIPSOCKETHANDLERBASE_PROCESSFIRSTRECEIVEDCHUNKL, "Received data" ); |
|
826 OstTraceData( TRACE_DUMP, DUP2_CPTPIPSOCKETHANDLERBASE_PROCESSFIRSTRECEIVEDCHUNKL, |
|
827 "%x", iReceiveChunkData.Ptr(), iReceiveChunkData.Size()); |
747 #endif |
828 #endif |
|
829 |
748 |
830 |
749 // Commit the received data if required. |
831 // Commit the received data if required. |
750 if (iReceiveDataCommit) |
832 if (iReceiveDataCommit) |
751 { |
833 { |
752 __FLOG(_L8("Commiting write data chunk")); |
834 OstTrace0( TRACE_NORMAL, DUP3_CPTPIPSOCKETHANDLERBASE_PROCESSFIRSTRECEIVEDCHUNKL, "Commiting write data chunk" ); |
|
835 |
753 iReceiveDataSink->CommitChunkL(iReceiveChunkData); |
836 iReceiveDataSink->CommitChunkL(iReceiveChunkData); |
754 } |
837 } |
755 } |
838 } |
756 else |
839 else |
757 { |
840 { |
758 ResumeReceiveDataStreamL(); |
841 ResumeReceiveDataStreamL(); |
759 } |
842 } |
760 |
843 |
761 __FLOG(_L8("ProcessFirstReceivedChunkL - Exit")); |
844 OstTraceFunctionExit0( CPTPIPSOCKETHANDLERBASE_PROCESSFIRSTRECEIVEDCHUNKL_EXIT ); |
762 } |
845 } |
763 |
846 |
764 |
847 |
765 |
848 |
766 /** |
849 /** |
767 Called after the first chunk has been received and we are expecting more packets. |
850 Called after the first chunk has been received and we are expecting more packets. |
768 This will be called repeatedly until all the packets have been received. |
851 This will be called repeatedly until all the packets have been received. |
769 */ |
852 */ |
770 void CPTPIPSocketHandlerBase::ResumeReceiveDataStreamL() |
853 void CPTPIPSocketHandlerBase::ResumeReceiveDataStreamL() |
771 { |
854 { |
772 __FLOG(_L8("ResumeReceiveDataStreamL - Entry")); |
855 OstTraceFunctionEntry0( CPTPIPSOCKETHANDLERBASE_RESUMERECEIVEDATASTREAML_ENTRY ); |
773 TBool endStream(EFalse); |
856 TBool endStream(EFalse); |
774 MMTPType *needCommit = NULL; |
857 MMTPType *needCommit = NULL; |
775 |
858 |
776 // Process the received chunk (if any). |
859 // Process the received chunk (if any). |
777 iPTPPacketLengthReceived += iReceiveData.Length(); |
860 iPTPPacketLengthReceived += iReceiveData.Length(); |
778 __FLOG_VA((_L8("Data received = iPTPPacketLengthReceived = %d bytes, Data expected = iPTPPacketLength = %d"), iPTPPacketLengthReceived, iPTPPacketLength)); |
861 OstTraceExt2( TRACE_NORMAL, DUP1_CPTPIPSOCKETHANDLERBASE_RESUMERECEIVEDATASTREAML, "Data received = iPTPPacketLengthReceived = %d bytes, Data expected = iPTPPacketLength = %d", |
|
862 iPTPPacketLengthReceived, iPTPPacketLength); |
|
863 |
779 |
864 |
780 if (iPTPPacketLengthReceived == iPTPPacketLength) |
865 if (iPTPPacketLengthReceived == iPTPPacketLength) |
781 { |
866 { |
782 SetState(EReceiveComplete); |
867 SetState(EReceiveComplete); |
783 endStream = ETrue; |
868 endStream = ETrue; |
828 { |
918 { |
829 |
919 |
830 iChunkStatus = iReceiveDataSink->NextWriteChunk(iReceiveChunkData); |
920 iChunkStatus = iReceiveDataSink->NextWriteChunk(iReceiveChunkData); |
831 |
921 |
832 } |
922 } |
833 __FLOG_VA((_L8("iReceiveChunkData pointer address is %08x"), iReceiveChunkData.Ptr())); |
923 OstTrace1( TRACE_NORMAL, DUP5_CPTPIPSOCKETHANDLERBASE_RESUMERECEIVEDATASTREAML, "iReceiveChunkData pointer address is %08x", |
|
924 iReceiveChunkData.Ptr()); |
|
925 |
834 break; |
926 break; |
835 |
927 |
836 case EReceiveComplete: |
928 case EReceiveComplete: |
837 __FLOG(_L8("Write data chunk sequence complet")); |
929 OstTrace0( TRACE_NORMAL, DUP6_CPTPIPSOCKETHANDLERBASE_RESUMERECEIVEDATASTREAML, "Write data chunk sequence complet" ); |
|
930 |
838 break; |
931 break; |
839 |
932 |
840 case EIdle: |
933 case EIdle: |
841 default: |
934 default: |
842 __FLOG(_L8("Invalid stream state")); |
935 OstTrace0( TRACE_NORMAL, DUP7_CPTPIPSOCKETHANDLERBASE_RESUMERECEIVEDATASTREAML, "Invalid stream state" ); |
|
936 |
843 Panic(EPTPIPBadState); |
937 Panic(EPTPIPBadState); |
844 break; |
938 break; |
845 } |
939 } |
846 |
940 |
847 __FLOG_VA((_L8("Chunk status = %d"), iChunkStatus)); |
941 OstTrace1( TRACE_NORMAL, DUP8_CPTPIPSOCKETHANDLERBASE_RESUMERECEIVEDATASTREAML, "Chunk status = %d", |
|
942 iChunkStatus); |
|
943 |
848 |
944 |
849 |
945 |
850 // If necessary, process the next chunk. |
946 // If necessary, process the next chunk. |
851 if (iState != EReceiveComplete) |
947 if (iState != EReceiveComplete) |
852 { |
948 { |
853 __FLOG_VA((_L8("Receive chunk capacity = %d bytes, length = %d bytes"), iReceiveChunkData.MaxLength(), iReceiveChunkData.Length())); |
949 OstTraceExt2( TRACE_NORMAL, DUP9_CPTPIPSOCKETHANDLERBASE_RESUMERECEIVEDATASTREAML, "Receive chunk capacity = %d bytes, length = %d bytes", |
854 __FLOG_VA((_L8("iReceiveChunkData pointer address is %08x"), iReceiveChunkData.Ptr())); |
950 iReceiveChunkData.MaxLength(), iReceiveChunkData.Length()); |
|
951 |
|
952 OstTrace1( TRACE_NORMAL, DUP10_CPTPIPSOCKETHANDLERBASE_RESUMERECEIVEDATASTREAML, "iReceiveChunkData pointer address is %08x", |
|
953 iReceiveChunkData.Ptr()); |
|
954 |
855 |
955 |
856 |
956 |
857 // When we reach the end of receiving a PTPIP packet, it is possible that our PTPIP chunk |
957 // When we reach the end of receiving a PTPIP packet, it is possible that our PTPIP chunk |
858 // length is greater than the actual data that is expected. |
958 // length is greater than the actual data that is expected. |
859 // eg when parameters 1to 5 are not set in a PTPIP request. In this case |
959 // eg when parameters 1to 5 are not set in a PTPIP request. In this case |
871 0, |
971 0, |
872 iReceiveChunkData.MaxLength() - iReceiveChunkData.Length()); |
972 iReceiveChunkData.MaxLength() - iReceiveChunkData.Length()); |
873 } |
973 } |
874 |
974 |
875 |
975 |
|
976 OstTrace1( TRACE_NORMAL, DUP11_CPTPIPSOCKETHANDLERBASE_RESUMERECEIVEDATASTREAML, "Length read this time is= %d", iReceiveData.MaxLength()); |
|
977 |
876 |
978 |
877 __FLOG_VA((_L8("Length read this time is= %d"), iReceiveData.MaxLength())); |
|
878 |
|
879 |
979 |
880 iSocket.Recv(iReceiveData, 0, iStatus); |
980 iSocket.Recv(iReceiveData, 0, iStatus); |
881 #ifdef MTP_DEBUG_FLOG_HEX_DUMP |
981 |
882 __FLOG_HEXDUMP((iReceiveData, _L8("Received data on socket "))); |
982 #ifdef MTP_DEBUG_OST_HEX_DUMP |
883 #endif |
983 OstTrace0( TRACE_NORMAL, DUP12_CPTPIPSOCKETHANDLERBASE_RESUMERECEIVEDATASTREAML, "Received data on socket " ); |
|
984 OstTraceData( TRACE_DUMP, DUP13_CPTPIPSOCKETHANDLERBASE_RESUMERECEIVEDATASTREAML, |
|
985 "%x", iReceiveData.Ptr(), iReceiveData.Size()); |
|
986 #endif |
|
987 |
884 SetActive(); |
988 SetActive(); |
885 __FLOG(_L8("Request issued")); |
989 OstTrace0( TRACE_NORMAL, CPTPIPSOCKETHANDLERBASE_RESUMERECEIVEDATASTREAML, "Request issued" ); |
|
990 |
886 } |
991 } |
887 if(needCommit != NULL) |
992 if(needCommit != NULL) |
888 { |
993 { |
889 TPtr8 tmp(NULL, 0, 0); |
994 TPtr8 tmp(NULL, 0, 0); |
890 needCommit->CommitChunkL(tmp); |
995 needCommit->CommitChunkL(tmp); |
891 } |
996 } |
892 __FLOG(_L8("ResumeReceiveDataStreamL - Exit")); |
997 OstTraceFunctionExit0( CPTPIPSOCKETHANDLERBASE_RESUMERECEIVEDATASTREAML_EXIT ); |
893 } |
998 } |
894 |
999 |
895 /** |
1000 /** |
896 Signals the data transfer controller that an asynchronous data receive sequence |
1001 Signals the data transfer controller that an asynchronous data receive sequence |
897 has completed. |
1002 has completed. |
899 @panic EPTPIPNotSupported In debug builds only, if the derived class has not fully |
1004 @panic EPTPIPNotSupported In debug builds only, if the derived class has not fully |
900 implemented the receive data path. |
1005 implemented the receive data path. |
901 */ |
1006 */ |
902 void CPTPIPSocketHandlerBase::ReceiveDataCompleteL(TInt /*aError*/, MMTPType& /*aSink*/) |
1007 void CPTPIPSocketHandlerBase::ReceiveDataCompleteL(TInt /*aError*/, MMTPType& /*aSink*/) |
903 { |
1008 { |
904 __FLOG(_L8("CSocketHandler::ReceiveDataCompleteL - Entry")); |
1009 OstTraceFunctionEntry0( CPTPIPSOCKETHANDLERBASE_RECEIVEDATACOMPLETEL_ENTRY ); |
905 __DEBUG_ONLY(Panic(EPTPIPNotSupported)); |
1010 __DEBUG_ONLY(Panic(EPTPIPNotSupported)); |
906 __FLOG(_L8("CSocketHandler::ReceiveDataCompleteL - Exit")); |
1011 OstTraceFunctionExit0( CPTPIPSOCKETHANDLERBASE_RECEIVEDATACOMPLETEL_EXIT ); |
907 } |
1012 } |
908 |
1013 |
909 /** |
1014 /** |
910 Forces the completion of a transfer in progress. |
1015 Forces the completion of a transfer in progress. |
911 |
1016 |
912 @param aReason error code describing the reason for cancelling. |
1017 @param aReason error code describing the reason for cancelling. |
913 @leave Any of the system wide error codes. |
1018 @leave Any of the system wide error codes. |
914 */ |
1019 */ |
915 void CPTPIPSocketHandlerBase::CancelReceiveL(TInt aReason) |
1020 void CPTPIPSocketHandlerBase::CancelReceiveL(TInt aReason) |
916 { |
1021 { |
917 __FLOG(_L8("CSocketHandler::CancelReceiveL - Entry")); |
1022 OstTraceFunctionEntry0( CPTPIPSOCKETHANDLERBASE_CANCELRECEIVEL_ENTRY ); |
918 |
1023 |
919 if (DataStreamDirection() == EReceivingState) |
1024 if (DataStreamDirection() == EReceivingState) |
920 { |
1025 { |
921 __FLOG(_L8("Cancel in EReceivingState")); |
1026 OstTrace0( TRACE_NORMAL, CPTPIPSOCKETHANDLERBASE_CANCELRECEIVEL, "Cancel in EReceivingState" ); |
|
1027 |
922 // Cancel any outstanding request. |
1028 // Cancel any outstanding request. |
923 Cancel(); |
1029 Cancel(); |
924 |
1030 |
925 // Notify the connection and reset the receive data stream. |
1031 // Notify the connection and reset the receive data stream. |
926 ResetReceiveDataStream(); |
1032 ResetReceiveDataStream(); |
927 ReceiveDataCompleteL(aReason, *iReceiveDataSink); |
1033 ReceiveDataCompleteL(aReason, *iReceiveDataSink); |
928 } |
1034 } |
929 |
1035 |
930 __FLOG(_L8("CSocketHandler::CancelReceiveL - Exit")); |
1036 OstTraceFunctionExit0( CPTPIPSOCKETHANDLERBASE_CANCELRECEIVEL_EXIT ); |
931 } |
1037 } |
932 |
1038 |
933 // |
1039 // |
934 // Getters , Setters and other helper functions |
1040 // Getters , Setters and other helper functions |
935 // |
1041 // |
936 |
1042 |
937 CPTPIPConnection& CPTPIPSocketHandlerBase::Connection() |
1043 CPTPIPConnection& CPTPIPSocketHandlerBase::Connection() |
938 { |
1044 { |
|
1045 OstTraceFunctionEntry0( CPTPIPSOCKETHANDLERBASE_CONNECTION_ENTRY ); |
|
1046 OstTraceFunctionExit0( CPTPIPSOCKETHANDLERBASE_CONNECTION_EXIT ); |
939 return iConnection; |
1047 return iConnection; |
940 } |
1048 } |
941 |
1049 |
942 RSocket& CPTPIPSocketHandlerBase::Socket() |
1050 RSocket& CPTPIPSocketHandlerBase::Socket() |
943 { |
1051 { |
|
1052 OstTraceFunctionEntry0( CPTPIPSOCKETHANDLERBASE_SOCKET_ENTRY ); |
|
1053 OstTraceFunctionExit0( CPTPIPSOCKETHANDLERBASE_SOCKET_EXIT ); |
944 return iSocket; |
1054 return iSocket; |
945 } |
1055 } |
946 |
1056 |
947 |
1057 |
948 void CPTPIPSocketHandlerBase::ResetSendDataStream() |
1058 void CPTPIPSocketHandlerBase::ResetSendDataStream() |
949 { |
1059 { |
950 __FLOG(_L8("CSocketHandler::ResetSendDataStream - Entry")); |
1060 OstTraceFunctionEntry0( CPTPIPSOCKETHANDLERBASE_RESETSENDDATASTREAM_ENTRY ); |
951 iSendChunkData.Set(NULL, 0); |
1061 iSendChunkData.Set(NULL, 0); |
952 iSendData.Set(NULL, 0); |
1062 iSendData.Set(NULL, 0); |
953 iSendDataSource = NULL; |
1063 iSendDataSource = NULL; |
954 iCancelReceived = EFalse; |
1064 iCancelReceived = EFalse; |
955 SetState(EIdle); |
1065 SetState(EIdle); |
956 __FLOG(_L8("CSocketHandler::ResetSendDataStream - Exit")); |
1066 OstTraceFunctionExit0( CPTPIPSOCKETHANDLERBASE_RESETSENDDATASTREAM_EXIT ); |
957 } |
1067 } |
958 |
1068 |
959 void CPTPIPSocketHandlerBase::ResetReceiveDataStream() |
1069 void CPTPIPSocketHandlerBase::ResetReceiveDataStream() |
960 { |
1070 { |
961 __FLOG(_L8("CSocketHandler::ResetReceiveDataStream - Entry")); |
1071 OstTraceFunctionEntry0( CPTPIPSOCKETHANDLERBASE_RESETRECEIVEDATASTREAM_ENTRY ); |
962 iReceiveChunkData.Set(NULL, 0, 0); |
1072 iReceiveChunkData.Set(NULL, 0, 0); |
963 iReceiveData.Set(NULL, 0, 0); |
1073 iReceiveData.Set(NULL, 0, 0); |
964 iReceiveDataSink = NULL; |
1074 iReceiveDataSink = NULL; |
965 iCancelReceived = EFalse; |
1075 iCancelReceived = EFalse; |
966 SetState(EIdle); |
1076 SetState(EIdle); |
967 __FLOG(_L8("CSocketHandler::ResetReceiveDataStream - Exit")); |
1077 OstTraceFunctionExit0( CPTPIPSOCKETHANDLERBASE_RESETRECEIVEDATASTREAM_EXIT ); |
968 } |
1078 } |
969 |
1079 |
970 |
1080 |
971 void CPTPIPSocketHandlerBase::SetState(TSocketState aState) |
1081 void CPTPIPSocketHandlerBase::SetState(TSocketState aState) |
972 { |
1082 { |
973 __FLOG(_L8("SetState - Entry")); |
1083 OstTraceFunctionEntry0( CPTPIPSOCKETHANDLERBASE_SETSTATE_ENTRY ); |
974 iState = aState; |
1084 iState = aState; |
975 __FLOG_VA((_L8(" state = 0x%08X"), iState)); |
1085 OstTrace1( TRACE_NORMAL, CPTPIPSOCKETHANDLERBASE_SETSTATE, "state = 0x%08X", |
976 __FLOG(_L8("SetState - Exit")); |
1086 iState); |
|
1087 |
|
1088 OstTraceFunctionExit0( CPTPIPSOCKETHANDLERBASE_SETSTATE_EXIT ); |
977 } |
1089 } |
978 |
1090 |
979 void CPTPIPSocketHandlerBase::CompleteSelf(TInt aCompletionCode) |
1091 void CPTPIPSocketHandlerBase::CompleteSelf(TInt aCompletionCode) |
980 { |
1092 { |
|
1093 OstTraceFunctionEntry0( CPTPIPSOCKETHANDLERBASE_COMPLETESELF_ENTRY ); |
981 SetActive(); |
1094 SetActive(); |
982 TRequestStatus* stat = &iStatus; |
1095 TRequestStatus* stat = &iStatus; |
983 User::RequestComplete(stat, aCompletionCode); |
1096 User::RequestComplete(stat, aCompletionCode); |
|
1097 OstTraceFunctionExit0( CPTPIPSOCKETHANDLERBASE_COMPLETESELF_EXIT ); |
984 } |
1098 } |
985 |
1099 |
986 /** |
1100 /** |
987 Provides the current data stream direction, sending or receiving |
1101 Provides the current data stream direction, sending or receiving |
988 */ |
1102 */ |
989 TInt32 CPTPIPSocketHandlerBase::DataStreamDirection() const |
1103 TInt32 CPTPIPSocketHandlerBase::DataStreamDirection() const |
990 { |
1104 { |
|
1105 OstTraceFunctionEntry0( CPTPIPSOCKETHANDLERBASE_DATASTREAMDIRECTION_ENTRY ); |
|
1106 OstTraceFunctionExit0( CPTPIPSOCKETHANDLERBASE_DATASTREAMDIRECTION_EXIT ); |
991 return (iState & EStateDirection); |
1107 return (iState & EStateDirection); |
992 } |
1108 } |
993 |
1109 |
994 void CPTPIPSocketHandlerBase::SetSocket(RSocket& aSocket) |
1110 void CPTPIPSocketHandlerBase::SetSocket(RSocket& aSocket) |
995 { |
1111 { |
|
1112 OstTraceFunctionEntry0( CPTPIPSOCKETHANDLERBASE_SETSOCKET_ENTRY ); |
996 iSocket = aSocket; |
1113 iSocket = aSocket; |
|
1114 OstTraceFunctionExit0( CPTPIPSOCKETHANDLERBASE_SETSOCKET_EXIT ); |
997 } |
1115 } |
998 |
1116 |
999 /** |
1117 /** |
1000 Ignore any errors in setting the socket options |
1118 Ignore any errors in setting the socket options |
1001 */ |
1119 */ |
1002 void CPTPIPSocketHandlerBase::SetSocketOptions() |
1120 void CPTPIPSocketHandlerBase::SetSocketOptions() |
1003 { |
1121 { |
|
1122 OstTraceFunctionEntry0( CPTPIPSOCKETHANDLERBASE_SETSOCKETOPTIONS_ENTRY ); |
1004 TInt error=iSocket.SetOpt(KSoTcpKeepAlive,KSolInetTcp,1); |
1123 TInt error=iSocket.SetOpt(KSoTcpKeepAlive,KSolInetTcp,1); |
1005 __FLOG_VA((_L8(" setting the keep alive option returned = %d"), error)); |
1124 OstTrace1( TRACE_NORMAL, CPTPIPSOCKETHANDLERBASE_SETSOCKETOPTIONS, "setting the keep alive option returned = %d", error ); |
|
1125 |
1006 error=iSocket.SetOpt(KSoTcpNoDelay,KSolInetTcp,1); |
1126 error=iSocket.SetOpt(KSoTcpNoDelay,KSolInetTcp,1); |
1007 __FLOG_VA((_L8(" setting the no delay to disable Nagle's algo returned %d"), error)); |
1127 OstTrace1( TRACE_NORMAL, DUP1_CPTPIPSOCKETHANDLERBASE_SETSOCKETOPTIONS, "setting the no delay to disable Nagle's algo returned %d", error ); |
1008 } |
1128 |
|
1129 OstTraceFunctionExit0( CPTPIPSOCKETHANDLERBASE_SETSOCKETOPTIONS_EXIT ); |
|
1130 } |