mtptransports/mtpptpiptransport/ptpipplugin/src/cptpipsockhandlerbase.cpp
changeset 49 c20dd21d1eb4
parent 0 d0791faffa3f
equal deleted inserted replaced
41:2c19c7cf5550 49:c20dd21d1eb4
    17 
    17 
    18 /**
    18 /**
    19  @internalComponent
    19  @internalComponent
    20 */
    20 */
    21 
    21 
       
    22 #include "mtpdebug.h"
    22 #include "cptpipsockhandlerbase.h"
    23 #include "cptpipsockhandlerbase.h"
    23 #include "cptpipconnection.h"
    24 #include "cptpipconnection.h"
    24 #include "ptpippanic.h"
    25 #include "ptpippanic.h"
       
    26 #include "OstTraceDefinitions.h"
       
    27 #ifdef OST_TRACE_COMPILER_IN_USE
       
    28 #include "cptpipsockhandlerbaseTraces.h"
       
    29 #endif
       
    30 
    25 
    31 
    26 const TUint32 KPTPIPHeaderSize = 8;
    32 const TUint32 KPTPIPHeaderSize = 8;
    27 const TUint KMaxPacketSixe   = 16;
    33 const TUint KMaxPacketSixe   = 16;
    28 const TUint64 KMaxPTPIPPacketSize = 0x18FF4; // 100 KB - 12
    34 const TUint64 KMaxPTPIPPacketSize = 0x18FF4; // 100 KB - 12
    29 
    35 
    30 //#define MTP_DEBUG_FLOG_HEX_DUMP
    36 //#define MTP_DEBUG_OST_HEX_DUMP 
    31 
    37 
    32 #define UNUSED_VAR(a) (a)=(a)
    38 #define UNUSED_VAR(a) (a)=(a)
    33 
    39 
    34 /**
    40 /**
    35 Constructor 
    41 Constructor 
    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 
   146             MMTPType& data(*iReceiveDataSink);
   154             MMTPType& data(*iReceiveDataSink);
   147             ResetReceiveDataStream();
   155             ResetReceiveDataStream();
   148             TRAPD(err, ReceiveDataCompleteL(iStatus.Int(), data));
   156             TRAPD(err, ReceiveDataCompleteL(iStatus.Int(), data));
   149             if (err != KErrNone)
   157             if (err != KErrNone)
   150             	{
   158             	{
   151             	__FLOG_VA((_L8("Framework threw an error from ReceiveDataCompleteL = %d"), err)); 
   159             	OstTrace1( TRACE_NORMAL, DUP3_CPTPIPSOCKETHANDLERBASE_RUNL, "Framework threw an error from ReceiveDataCompleteL = %d",
       
   160             	        err);
       
   161             	
   152             	ReceiveDataCompleteL(err, data);
   162             	ReceiveDataCompleteL(err, data);
   153             	}
   163             	}
   154             }
   164             }
   155         break;
   165         break;
   156         
   166         
   160 			{
   170 			{
   161 			ResetSendDataStream();
   171 			ResetSendDataStream();
   162 			break;
   172 			break;
   163 			}
   173 			}
   164 
   174 
   165         __FLOG_VA((_L8("Send data stream completion status = %d"), iStatus.Int())); 
   175         OstTrace1( TRACE_NORMAL, DUP4_CPTPIPSOCKETHANDLERBASE_RUNL, "Send data stream completion status = %d",
       
   176                 iStatus.Int());
       
   177         
   166         if (iStatus != KErrNone)
   178         if (iStatus != KErrNone)
   167             {
   179             {
   168             // Abnormal completion.
   180             // Abnormal completion.
   169             SetState(ESendComplete);
   181             SetState(ESendComplete);
   170             }
   182             }
   178             const MMTPType& data(*iSendDataSource);
   190             const MMTPType& data(*iSendDataSource);
   179             ResetSendDataStream();
   191             ResetSendDataStream();
   180             TRAPD(err, SendDataCompleteL(iStatus.Int(), data));
   192             TRAPD(err, SendDataCompleteL(iStatus.Int(), data));
   181             if (err != KErrNone)
   193             if (err != KErrNone)
   182             	{
   194             	{
   183             	__FLOG_VA((_L8("Framework threw an error from SendDataCompleteL = %d"), err)); 
   195             	OstTrace1( TRACE_NORMAL, DUP5_CPTPIPSOCKETHANDLERBASE_RUNL, "Framework threw an error from SendDataCompleteL = %d",
       
   196             	        err);
       
   197             	
   184             	SendDataCompleteL(err, data);
   198             	SendDataCompleteL(err, data);
   185             	}
   199             	}
   186             }
   200             }
   187         break;
   201         break;
   188         
   202         
   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);
   302 	else 
   326 	else 
   303 		{
   327 		{
   304 		Connection().HandleError(aError);
   328 		Connection().HandleError(aError);
   305 		}
   329 		}
   306  
   330  
   307 	__FLOG(_L8("RunError - Exit"));
   331 	OstTraceFunctionExit0( CPTPIPSOCKETHANDLERBASE_RUNERROR_EXIT );
   308 	return KErrNone;
   332 	return KErrNone;
   309 	}
   333 	}
   310 	
   334 	
   311 //
   335 //
   312 // Send Data Functions
   336 // Send Data Functions
   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)
   457                 }
   496                 }
   458             else
   497             else
   459                 {
   498                 {
   460                 consumedLen = chunkAvailableLen;
   499                 consumedLen = chunkAvailableLen;
   461                 }
   500                 }
   462             __FLOG_VA((_L8("Buffering %d bytes"), consumedLen));
   501             OstTrace1( TRACE_NORMAL, DUP8_CPTPIPSOCKETHANDLERBASE_PROCESSSENDDATAL, "Buffering %d bytes",
       
   502                     consumedLen);
       
   503             
   463             iPacketBuffer.Append(iSendChunkData.Left(consumedLen));
   504             iPacketBuffer.Append(iSendChunkData.Left(consumedLen));
   464             
   505             
   465             // Update the available chunk data to reflect only the unconsumed portion.
   506             // Update the available chunk data to reflect only the unconsumed portion.
   466             __FLOG_VA((_L8("Residual chunk data = %d bytes"), unconsumedLen));
   507             OstTrace0( TRACE_NORMAL, DUP9_CPTPIPSOCKETHANDLERBASE_PROCESSSENDDATAL, "CPTPIPSocketHandlerBase::ProcessSendDataL" );
       
   508             
   467             if (unconsumedLen)
   509             if (unconsumedLen)
   468                 {
   510                 {
   469                 iSendChunkData.Set(iSendChunkData.Right(unconsumedLen));
   511                 iSendChunkData.Set(iSendChunkData.Right(unconsumedLen));
   470                 }
   512                 }
   471             else
   513             else
   491             }
   533             }
   492     
   534     
   493         // Buffer the chunk data packet residual portion.
   535         // Buffer the chunk data packet residual portion.
   494         if (chunkResidualLen)
   536         if (chunkResidualLen)
   495             {
   537             {
   496             __FLOG_VA((_L8("Buffering %d bytes"), chunkResidualLen));
   538             OstTrace1( TRACE_NORMAL, DUP10_CPTPIPSOCKETHANDLERBASE_PROCESSSENDDATAL, "Buffering %d bytes",
       
   539                     chunkResidualLen);
       
   540             
       
   541             
   497             iPacketBuffer.Append(iSendChunkData.Right(chunkResidualLen));  
   542             iPacketBuffer.Append(iSendChunkData.Right(chunkResidualLen));  
   498             }
   543             }
   499             
   544             
   500         // All data has been consumed and/or buffered.
   545         // All data has been consumed and/or buffered.
   501         iSendChunkData.Set(NULL, 0);
   546         iSendChunkData.Set(NULL, 0);
   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);
   571 		    case KMTPChunkSequenceCompletion:
   629 		    case KMTPChunkSequenceCompletion:
   572 		    	iPTPIPDataHeader->SetUint32L(CPTPIPDataContainer::EPacketType, EPTPIPPacketTypeEndData);
   630 		    	iPTPIPDataHeader->SetUint32L(CPTPIPDataContainer::EPacketType, EPTPIPPacketTypeEndData);
   573 		        break;
   631 		        break;
   574 		        
   632 		        
   575 		    default:
   633 		    default:
   576 		    	__FLOG(_L8("PTPIP Error :chunkStatus returned an error"));
   634 		    	OstTrace0( TRACE_NORMAL, DUP2_CPTPIPSOCKETHANDLERBASE_CREATEANDSENDDATAPACKETSL, "PTPIP Error :chunkStatus returned an error" );
   577 		        User::Leave(iChunkStatus);
   635 		    	
       
   636 		        LEAVEIFERROR(iChunkStatus, 
       
   637 		                            OstTrace1( TRACE_ERROR, CINTERNETCONNECTIONHANDLER_CONSTRUCTL, "iChunkStatus is %d", iChunkStatus ));
       
   638 
   578 		        break;
   639 		        break;
   579 		        } 
   640 		        } 
   580 			// Set the iSendData to point to the ptpip header. 
   641 			// Set the iSendData to point to the ptpip header. 
   581 			TInt ret = iPTPIPDataHeader->FirstReadChunk(iSendData);
   642 			TInt ret = iPTPIPDataHeader->FirstReadChunk(iSendData);
   582 			}
   643 			}
   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
   655 The buffer is provided by the fw in case its a data in.
   724 The buffer is provided by the fw in case its a data in.
   656 @param aSink The buffer into which the data from initiator will be received. 
   725 @param aSink The buffer into which the data from initiator will be received. 
   657 */
   726 */
   658 void CPTPIPSocketHandlerBase::ReceiveDataL(MMTPType& aSink)
   727 void CPTPIPSocketHandlerBase::ReceiveDataL(MMTPType& aSink)
   659 	{
   728 	{
   660 	__FLOG(_L8("ReceiveDataL - Entry"));
   729 	OstTraceFunctionEntry0( CPTPIPSOCKETHANDLERBASE_RECEIVEDATAL_ENTRY );
   661 	
   730 	
   662 	// Set the state 
   731 	// Set the state 
   663 	SetState(EReceiveInProgress);
   732 	SetState(EReceiveInProgress);
   664 	
   733 	
   665 	// The memory has come from the conection. In case it was a command receive
   734 	// The memory has come from the conection. In case it was a command receive
   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     
   727 	// If the PTPIP type is not one of the standard expected types, 
   805 	// If the PTPIP type is not one of the standard expected types, 
   728 	// or not expected in the current transaction phase then we stop further receiving
   806 	// or not expected in the current transaction phase then we stop further receiving
   729 	// This current RunL will 
   807 	// This current RunL will 
   730 	if (EPTPIPPacketTypeUndefined == iType ) 
   808 	if (EPTPIPPacketTypeUndefined == iType ) 
   731 		{
   809 		{
   732 		__FLOG(_L8("PTPIP ERROR: Unexpected value in the type field of PTPIP header, appears corrupt"));
   810 		OstTrace0( TRACE_NORMAL, CPTPIPSOCKETHANDLERBASE_PROCESSFIRSTRECEIVEDCHUNKL, "PTPIP ERROR: Unexpected value in the type field of PTPIP header, appears corrupt" );
       
   811 		
   733 		SetState(EReceiveComplete);
   812 		SetState(EReceiveComplete);
   734 		iStatus = KErrCorrupt;
   813 		iStatus = KErrCorrupt;
   735 		}
   814 		}
   736 	
   815 	
   737 	// If there is nothing to receive after the header, possible for probe packet.
   816 	// If there is nothing to receive after the header, possible for probe packet.
   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;
   785 	   	//if type  is data then end stream is not true
   870 	   	//if type  is data then end stream is not true
   786 	   	if (iType == EPTPIPPacketTypeData)
   871 	   	if (iType == EPTPIPPacketTypeData)
   787 	   	endStream = EFalse;
   872 	   	endStream = EFalse;
   788 	   	}
   873 	   	}
   789 
   874 
   790     __FLOG_VA((_L8("Received = %d bytes, write data chunk capacity = %d bytes"), iReceiveChunkData.Length(), iReceiveChunkData.MaxLength()));		   
   875     OstTraceExt2( TRACE_NORMAL, DUP2_CPTPIPSOCKETHANDLERBASE_RESUMERECEIVEDATASTREAML, "Received = %d bytes, write data chunk capacity = %d bytes",
   791 #ifdef MTP_DEBUG_FLOG_HEX_DUMP 
   876             iReceiveChunkData.Length(), iReceiveChunkData.MaxLength());
   792     __FLOG_HEXDUMP((iReceiveChunkData, _L8("Received data ")));
   877     
       
   878 #ifdef MTP_DEBUG_OST_HEX_DUMP
       
   879         OstTrace0( TRACE_NORMAL, DUP3_CPTPIPSOCKETHANDLERBASE_RESUMERECEIVEDATASTREAML, "Received data " );
       
   880         OstTraceData( TRACE_DUMP, DUP4_CPTPIPSOCKETHANDLERBASE_RESUMERECEIVEDATASTREAML, 
       
   881                 "%x", iReceiveChunkData.Ptr(), iReceiveChunkData.Size());
   793 #endif
   882 #endif
       
   883 
   794 
   884 
   795 
   885 
   796     // Commit the received data if required.
   886     // Commit the received data if required.
   797 	if (iReceiveDataCommit)
   887 	if (iReceiveDataCommit)
   798          {
   888          {
   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 	}