hti/HtiServicePlugins/HtiIpProxyServicePlugin/IPProxyEngine/Src/Csocketrouter.cpp
changeset 13 33016869e0dd
parent 0 a03f92240627
equal deleted inserted replaced
0:a03f92240627 13:33016869e0dd
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 
    19 
    20 // INCLUDE FILES
    20 // INCLUDE FILES
    21 #include "CSocketRouter.h"
    21 #include "Csocketrouter.h"
    22 #include "CommRouterDefinitions.h"
    22 #include "CommRouterDefinitions.h"
    23 #include "MSocketRouterObserver.h"
    23 #include "MSocketRouterObserver.h"
    24 #include "MBPProtocol.h"
    24 #include "MBPProtocol.h"
    25 #include "CProtocolTCP.h"
    25 #include "CProtocolTCP.h"
    26 #include "CProtocolUDP.h"
    26 #include "CProtocolUDP.h"
   213 
   213 
   214 // -----------------------------------------------------------------------------
   214 // -----------------------------------------------------------------------------
   215 // CSocketRouter::FindPeerSocket
   215 // CSocketRouter::FindPeerSocket
   216 // -----------------------------------------------------------------------------
   216 // -----------------------------------------------------------------------------
   217 //
   217 //
   218 TInt CSocketRouter::FindPeerSocket( TUint aRemotePort )
   218 TInt CSocketRouter::FindPeerSocket( TUint aPort )
   219     {
   219     {
   220     DEBUG_PRINT( DEBUG_STRING( "CSocketRouter::FindPeerSocket()" ) );
   220     DEBUG_PRINT( DEBUG_STRING( "CSocketRouter::FindPeerSocket()" ) );
   221     TInt count = iPeerSocketArray->Count();
   221     TInt count = iPeerSocketArray->Count();
   222     for ( TInt i = 0; i < count; i++ )
   222     for ( TInt i = 0; i < count; i++ )
   223         {
   223         {
   224         if ( iPeerSocketArray->At( i )->RemotePort() == aRemotePort )
   224         if ( iPeerSocketArray->At( i )->RemotePort() == aPort 
       
   225                 || iPeerSocketArray->At( i )->LocalPort() == aPort)
   225             {
   226             {
   226             return i;
   227             return i;
   227             }
   228             }
   228         }
   229         }
   229     return -1;
   230     return -1;
   646 
   647 
   647 // -----------------------------------------------------------------------------
   648 // -----------------------------------------------------------------------------
   648 // CSocketRouter::CloseTCPConnection
   649 // CSocketRouter::CloseTCPConnection
   649 // -----------------------------------------------------------------------------
   650 // -----------------------------------------------------------------------------
   650 //
   651 //
   651 void CSocketRouter::CloseTCPConnection( TUint aPort )
   652 void CSocketRouter::CloseTCPConnectionL( TUint aPort )
   652     {
   653     {
   653     DEBUG_PRINT( DEBUG_STRING( "CloseTCPConnection, port = %d" ), aPort );
   654     DEBUG_PRINT( DEBUG_STRING( "CloseTCPConnection, port = %d" ), aPort );
       
   655     
   654     // Close the socket if it exists
   656     // Close the socket if it exists
       
   657     CArrayPtr<CSocket>* socketArrayForDestroy = new (ELeave) CArrayPtrFlat<CSocket> ( 10 );
       
   658     CleanupStack::PushL(socketArrayForDestroy);
   655     TInt index = FindPeerSocket( aPort );
   659     TInt index = FindPeerSocket( aPort );
   656     if ( index > -1 )
   660     while ( index > -1 )
   657         {
   661         {
   658         RemovePeerSocket( index );
   662         socketArrayForDestroy->AppendL(iPeerSocketArray->At( index ));
   659         }
   663         iPeerSocketArray->Delete(index);
   660 
   664         index = FindPeerSocket( aPort );
   661     if ( iObserver && index > -1 )
   665         }
       
   666     socketArrayForDestroy->ResetAndDestroy();
       
   667     CleanupStack::PopAndDestroy(socketArrayForDestroy);
       
   668 
       
   669     if ( iObserver )
   662         {
   670         {
   663         iObserver->CloseTCPConnection( aPort );
   671         iObserver->CloseTCPConnection( aPort );
   664         }
   672         }
   665     }
   673     }
   666 
   674