datacommsserver/esockserver/test/protocols/ptestinternalsocket/src/protocolfamily.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2004-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 <es_prot.h>
       
    17 #include <e32test.h>
       
    18 #include "es_ptestinternalsocket.h"
       
    19 #include <comms-infras/nifif.h>
       
    20 #include <comms-infras/eintsock.h>
       
    21 #include <comms-infras/ss_roles.h>
       
    22 #include <nifman_internal.h>
       
    23 #include <es_mbuf.h>
       
    24 #include <ss_std.h>
       
    25 #include <ss_pman.h>
       
    26 #include <ss_glob.h>
       
    27 #include <e32math.h>
       
    28 #include <dns_qry.h>
       
    29 #include <agenterrors.h>
       
    30 #include <e32property.h>
       
    31 
       
    32 #include "proxyprotocol.h"
       
    33 
       
    34 #include "protocolfamily.h"
       
    35 
       
    36 extern "C"
       
    37 	{
       
    38 	IMPORT_C CProtocolFamilyBase* InstallProxy(void);	// Force export 
       
    39 
       
    40 	EXPORT_C CProtocolFamilyBase * InstallProxy(void)
       
    41 	//
       
    42 	// Create a new protocol family
       
    43 	//
       
    44 		{
       
    45 		return CTestIntSocketProtocolFamily::NewL();
       
    46 		}
       
    47 	}
       
    48 
       
    49 CTestIntSocketProtocolFamily* CTestIntSocketProtocolFamily::NewL()
       
    50 //
       
    51 //
       
    52 //
       
    53 	{
       
    54 	CTestIntSocketProtocolFamily* pf=new(ELeave) CTestIntSocketProtocolFamily();
       
    55 	CleanupStack::PushL(pf);
       
    56 	pf->ConstructL();
       
    57 	CleanupStack::Pop();
       
    58 	return pf;
       
    59 	}
       
    60 
       
    61 void CTestIntSocketProtocolFamily::ConstructL()
       
    62 //
       
    63 //
       
    64 //
       
    65 	{
       
    66 	// Force a fail on Memory tests
       
    67 	char* ptr=new(ELeave) char;
       
    68 	delete ptr;
       
    69 
       
    70 	}
       
    71 
       
    72 CTestIntSocketProtocolFamily::CTestIntSocketProtocolFamily() : CProtocolFamilyBase()
       
    73 	{
       
    74 	iProtocolDescs[0].iAddrFamily=KProxyAddrFamily;
       
    75 	iProtocolDescs[0].iSockType=KSockDatagram; // not important whether datagram or stream for proxy
       
    76 	iProtocolDescs[0].iProtocol=KProxy;
       
    77 	iProtocolDescs[0].iVersion=TVersion(KPTestIntSocketMajor,KPTestIntSocketMinor,KPTestIntSocketBuild);
       
    78 	iProtocolDescs[0].iByteOrder=EBigEndian;
       
    79 	iProtocolDescs[0].iServiceInfo=kDDatagramServiceInfo|KSIPeekData;
       
    80 	iProtocolDescs[0].iSecurity=KSocketNoSecurity;
       
    81 	iProtocolDescs[0].iMessageSize=0x300;
       
    82 	iProtocolDescs[0].iName=KProxyName;
       
    83 	iProtocolDescs[0].iServiceTypeInfo=ESocketSupport|ECantProcessMBufChains;
       
    84 	iProtocolDescs[0].iNamingServices=KNSNameResolution|KNSServiceResolution|KNSInfoDatabase;
       
    85 	iProtocolDescs[0].iNumSockets=100;
       
    86 /*
       
    87 	iProtocolDescs[1].iAddrFamily=KProxyAddrFamily;
       
    88 	iProtocolDescs[1].iSockType=KSockDatagram;
       
    89 	iProtocolDescs[1].iProtocol=KTargetDatagram;
       
    90 	iProtocolDescs[1].iVersion=TVersion(KPTestIntSocketMajor,KPTestIntSocketMinor,KPTestIntSocketBuild);
       
    91 	iProtocolDescs[1].iByteOrder=EBigEndian;
       
    92 	iProtocolDescs[1].iServiceInfo=kDDatagramServiceInfo|KSIPeekData;
       
    93 	iProtocolDescs[1].iSecurity=KSocketNoSecurity;
       
    94 	iProtocolDescs[1].iMessageSize=0x300;
       
    95 	iProtocolDescs[1].iName=KTargetDatagramName;
       
    96 	iProtocolDescs[1].iServiceTypeInfo=ESocketSupport|ECantProcessMBufChains;
       
    97 	iProtocolDescs[1].iNamingServices=KNSNameResolution|KNSServiceResolution|KNSInfoDatabase;
       
    98 	iProtocolDescs[1].iNumSockets=100;
       
    99 
       
   100 	iProtocolDescs[2].iAddrFamily=KProxyAddrFamily;
       
   101 	iProtocolDescs[2].iSockType=KSockStream;
       
   102 	iProtocolDescs[2].iProtocol=KTargetStream;
       
   103 	iProtocolDescs[2].iVersion=TVersion(KPTestIntSocketMajor,KPTestIntSocketMinor,KPTestIntSocketBuild);
       
   104 	iProtocolDescs[2].iByteOrder=EBigEndian;
       
   105 	iProtocolDescs[2].iServiceInfo=KDStreamServiceInfo;
       
   106 	iProtocolDescs[2].iSecurity=KSocketNoSecurity;
       
   107 	iProtocolDescs[2].iMessageSize=KSocketMessageSizeIsStream;
       
   108 	iProtocolDescs[2].iName=KTargetStreamName;
       
   109 	iProtocolDescs[2].iServiceTypeInfo=ESocketSupport|ECantProcessMBufChains;
       
   110 	iProtocolDescs[2].iNamingServices=0;
       
   111 	iProtocolDescs[2].iNumSockets=100;
       
   112 */
       
   113 	__DECLARE_NAME(_S("CTestIntSocketProtocolFamily"));
       
   114 	}
       
   115 
       
   116 #pragma warning( disable : 4100 )
       
   117 
       
   118 TInt CTestIntSocketProtocolFamily::Install()
       
   119 	{
       
   120 	// Force a fail on Memory tests
       
   121 	char* ptr=new char;
       
   122 	if (!ptr)
       
   123 		return KErrNoMemory;
       
   124 	delete ptr;
       
   125 	return KErrNone;
       
   126 	}
       
   127 
       
   128 TInt CTestIntSocketProtocolFamily::Remove()
       
   129 	{
       
   130 	return KErrNone;
       
   131 	}
       
   132 
       
   133 TUint CTestIntSocketProtocolFamily::ProtocolList(TServerProtocolDesc *& aProtocolDescPointer)
       
   134 	{
       
   135 	// Make sure we don't register the proxy protocol twice when testing two worker threads.
       
   136 	// We only need one instance and if we try to register a second, ESockSvr will panic the
       
   137 	// second worker thread with a misconfiguration error.
       
   138 	if(SockManGlobals::Get()->SelfWorker()->WorkerId() == KProxyWorkerTwoId)
       
   139 		{
       
   140 		aProtocolDescPointer = NULL;
       
   141 		
       
   142 		return 0;
       
   143 		}
       
   144  
       
   145   	aProtocolDescPointer=new TServerProtocolDesc[KPTestIntSocketNumProtocols];
       
   146   	if (!aProtocolDescPointer)
       
   147   		return 0;
       
   148 
       
   149 	Mem::Copy(aProtocolDescPointer, iProtocolDescs, sizeof(TServerProtocolDesc)*KPTestIntSocketNumProtocols);
       
   150 
       
   151 	TRAP_IGNORE(Nif::CheckInstalledMBufManagerL();)
       
   152 
       
   153 	return KPTestIntSocketNumProtocols;
       
   154 	};
       
   155 
       
   156 CProtocolBase * CTestIntSocketProtocolFamily::NewProtocolL(TUint /* aSockType */,TUint aProtocol)
       
   157 	{
       
   158 
       
   159 	CProtocolBase* p=CProxyProtocol::NewL(aProtocol, &iProtocolDescs[aProtocol-1]);	
       
   160 	return p;
       
   161 	}
       
   162 
       
   163 
       
   164