|
1 // Copyright (c) 2003-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 <chttptransportlayer.h> |
|
17 |
|
18 #include "cpipeliningtestserver.h" |
|
19 #include "httptestutils.h" |
|
20 #include "MPipeliningTestCase.h" |
|
21 #include "MPipeliningTestObserver.h" |
|
22 #include "CTestServerStreamManager.h" |
|
23 |
|
24 const TUint16 KListeningPort = 80; |
|
25 |
|
26 CPipeliningTestServer* CPipeliningTestServer::NewL(CHTTPTestUtils& aTestUtils, MPipeliningTestObserver& aObserver) |
|
27 { |
|
28 CPipeliningTestServer* self = new (ELeave) CPipeliningTestServer(aTestUtils, aObserver); |
|
29 CleanupStack::PushL(self); |
|
30 self->ConstructL(); |
|
31 CleanupStack::Pop(self); |
|
32 return self; |
|
33 } |
|
34 |
|
35 CPipeliningTestServer::CPipeliningTestServer(CHTTPTestUtils& aTestUtils, MPipeliningTestObserver& aObserver) |
|
36 : iTestUtils(aTestUtils), iObserver(aObserver) |
|
37 { |
|
38 } |
|
39 |
|
40 void CPipeliningTestServer::ConstructL() |
|
41 { |
|
42 _LIT8(KTxtTCP, "TCP"); |
|
43 THttpTransportConstructionParams params(*this); |
|
44 params.iPriority = EFalse; |
|
45 iTCPLayer = CHttpTransportLayer::NewL(KTxtTCP(), params); |
|
46 } |
|
47 |
|
48 CPipeliningTestServer::~CPipeliningTestServer() |
|
49 { |
|
50 StopServer(); |
|
51 iStreamManager.ResetAndDestroy(); |
|
52 iStreamManager.Close(); |
|
53 delete iTCPLayer; |
|
54 } |
|
55 |
|
56 void CPipeliningTestServer::StartServerL() |
|
57 { |
|
58 iTCPLayer->ListenL(*this, KListeningPort); |
|
59 } |
|
60 |
|
61 void CPipeliningTestServer::StopServer() |
|
62 { |
|
63 if( iTCPLayer!=NULL ) |
|
64 iTCPLayer->StopListen(); |
|
65 } |
|
66 |
|
67 void CPipeliningTestServer::ResetServer() |
|
68 { |
|
69 iStreamManager.ResetAndDestroy(); |
|
70 } |
|
71 |
|
72 void CPipeliningTestServer::SetTestCase(MPipeliningTestCase* aTestCase) |
|
73 { |
|
74 iTestCase = aTestCase; |
|
75 |
|
76 _LIT(KTxtTransCount, "Total transaction in test case = %d"); |
|
77 iTestUtils.LogIt(KTxtTransCount(), iTestCase->TotalTransactionCount()); |
|
78 |
|
79 _LIT(KTxtConnectionCount, "Total connections in test case = %d"); |
|
80 iTestUtils.LogIt(KTxtConnectionCount(), iTestCase->ConnectionCount()); |
|
81 } |
|
82 |
|
83 TInt CPipeliningTestServer::ConnectionCount() const |
|
84 { |
|
85 return iStreamManager.Count(); |
|
86 } |
|
87 |
|
88 // From MSocketListenObserver |
|
89 void CPipeliningTestServer::ConnectionReceivedL(MInputStream& aInputStream, MOutputStream& aOutputStream) |
|
90 { |
|
91 // New connection received, create a new stream manager to manage the requests and responses |
|
92 const TInt connectionCount = iStreamManager.Count(); |
|
93 |
|
94 CTestServerStreamManager* newStreamMgr = CTestServerStreamManager::NewL(iTestUtils, connectionCount, iTestCase, &aInputStream, &aOutputStream); |
|
95 CleanupStack::PushL(newStreamMgr); |
|
96 User::LeaveIfError(iStreamManager.Append(newStreamMgr)); |
|
97 CleanupStack::Pop(newStreamMgr); |
|
98 |
|
99 _LIT(KTxtConnection, "Server - Client connection received and connected."); |
|
100 iTestUtils.LogIt(KTxtConnection()); |
|
101 } |
|
102 |
|
103 TInt CPipeliningTestServer::HandleListenError(TInt aError) |
|
104 { |
|
105 _LIT(KTxtListenError, "Server listening error: Error code = %d"); |
|
106 iTestUtils.LogIt(KTxtListenError(), aError); |
|
107 |
|
108 iObserver.EndTest(aError); |
|
109 return KErrNone; |
|
110 } |
|
111 |
|
112 void CPipeliningTestServer::MSocketListenObserver_Reserved() |
|
113 { |
|
114 } |
|
115 |
|
116 // From MConnectionPrefsProvider |
|
117 TBool CPipeliningTestServer::SupplyCommsConnection(RConnection*& /*aConnectionPtr*/) |
|
118 { |
|
119 return EFalse; |
|
120 } |
|
121 |
|
122 void CPipeliningTestServer::SetCommsConnectionL(RConnection* /*aConnectionPtr*/) |
|
123 { |
|
124 // Do nothing |
|
125 } |
|
126 |
|
127 void CPipeliningTestServer::GetSecurityPrefs(TBool& aDialogPrompt, MSecurityPolicy*& aSecurityPolicy) |
|
128 { |
|
129 aDialogPrompt = EFalse; |
|
130 aSecurityPolicy = NULL; |
|
131 } |
|
132 |
|
133 TBool CPipeliningTestServer::ImmediateSocketShutdown() |
|
134 { |
|
135 return EFalse; |
|
136 } |
|
137 |
|
138 TInt CPipeliningTestServer::SessionId() |
|
139 { |
|
140 return KErrNotSupported; |
|
141 } |
|
142 |
|
143 TBool CPipeliningTestServer::SupplySocketServerHandle ( TInt& /*aSocketServerHandle*/ ) |
|
144 { |
|
145 return 0; |
|
146 } |
|
147 |
|
148 void CPipeliningTestServer::SetSocketServerHandleL ( TInt /*aSocketServerHandle*/ ) |
|
149 { |
|
150 // do nothing |
|
151 } |
|
152 |
|
153 TInt CPipeliningTestServer::GetRecvBufferSize() |
|
154 { |
|
155 return KDefaultBufferSize; |
|
156 } |
|
157 |