datacommsserver/esockserver/ssock/ss_mbufif.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <ss_std.h>
       
    17 #include <es_mbufif.h>
       
    18 #include <comms-infras/ss_flowbinders.h>
       
    19 
       
    20 using namespace ESock;
       
    21 
       
    22 // the CWaitForMBufs active object class is used to handle an out of mbufs 
       
    23 // condition during CServProviderBaseMBuf::Write. If a normal allocation fails 
       
    24 // then one of these AOs is created to wait on mbufs becomign available.
       
    25 //
       
    26 // when they are, this AO calls CanSend on the socket, which results
       
    27 // in Write being called, which should now be able to complete successfully.
       
    28 // 
       
    29 
       
    30 
       
    31 CWaitForMBufs* CWaitForMBufs::NewL(MSessionDataNotify* aSocket)
       
    32 	{
       
    33 	CWaitForMBufs* self = new(ELeave) CWaitForMBufs(aSocket);
       
    34 	CleanupStack::PushL(self);
       
    35 	self->ConstructL();
       
    36 	CleanupStack::Pop();
       
    37 	return self;
       
    38 	}
       
    39 
       
    40 CWaitForMBufs::CWaitForMBufs(MSessionDataNotify* aSocket) 
       
    41 : CActive(0),
       
    42   iSocket(aSocket)
       
    43 	{
       
    44 	}
       
    45 
       
    46 void CWaitForMBufs::ConstructL()
       
    47 	{
       
    48 	CActiveScheduler::Add(this);
       
    49 	}
       
    50 
       
    51 CWaitForMBufs::~CWaitForMBufs()  
       
    52 	{
       
    53 	Cancel();
       
    54 	iMBufChain.Free();
       
    55 	}
       
    56 
       
    57 // from CActive
       
    58 void CWaitForMBufs::RunL()     
       
    59 	{
       
    60 	iMBufChain.Free();
       
    61 	if(iSignalCanSend)
       
    62 		{
       
    63 		iSignalCanSend = EFalse;  //Has to be before because CanSend can re-request
       
    64 		iSocket->CanSend();
       
    65 		}
       
    66 	if(iSignalNewData)
       
    67 		{
       
    68 		iSignalNewData = EFalse;  //Has to be before because CanSend can re-request
       
    69 		iSocket->NewData(0);
       
    70 		}
       
    71 	}
       
    72 
       
    73 void CWaitForMBufs::DoCancel() 
       
    74 	{
       
    75 		iSignalNewData = EFalse;  
       
    76 		iSignalCanSend = EFalse;
       
    77 		iRequest.Cancel();
       
    78 	}
       
    79 
       
    80 // requests
       
    81 
       
    82 void CWaitForMBufs::CancelNewData() 
       
    83 	{
       
    84 	iSignalNewData = EFalse;  
       
    85 	if (!iSignalNewData && !iSignalCanSend)
       
    86 		{
       
    87 		iRequest.Cancel();
       
    88 		}
       
    89 	}
       
    90 
       
    91 void CWaitForMBufs::CancelCanSend() 
       
    92 	{
       
    93 	iSignalCanSend = EFalse;
       
    94 	if (!iSignalNewData && !iSignalCanSend)
       
    95 		{
       
    96 		iRequest.Cancel();
       
    97 		}
       
    98 	}
       
    99 	
       
   100 void CWaitForMBufs::AllocWaitAndSignalNewData(TUint aSize)
       
   101 
       
   102 	{
       
   103 	if(!IsActive())
       
   104 		{
       
   105 		iRequest.Alloc(iMBufChain, aSize, iStatus);
       
   106 		SetActive();
       
   107 		}
       
   108 	iSignalNewData = ETrue;
       
   109 	}
       
   110 
       
   111 void CWaitForMBufs::AllocWaitAndSignalCanSend(TUint aSize)
       
   112 	{
       
   113 	if(!IsActive())
       
   114 		{
       
   115 		iRequest.Alloc(iMBufChain, aSize, iStatus);
       
   116 		SetActive();
       
   117 		}
       
   118 	iSignalCanSend = ETrue;
       
   119 	}
       
   120