1 /* |
|
2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 /** @file |
|
19 @internalComponent |
|
20 @test |
|
21 */ |
|
22 |
|
23 #ifndef TCPTEST_H |
|
24 #define TCPTEST_H |
|
25 |
|
26 #include <e32cons.h> |
|
27 #include <es_sock.h> |
|
28 #include <in_sock.h> |
|
29 |
|
30 class CTcpProcess : public CActive |
|
31 /** |
|
32 Run TCP test: Create a tcp connection and make data transfer on it. |
|
33 */ |
|
34 { |
|
35 public: |
|
36 static CTcpProcess* NewL(CConsoleBase& aConsole, TInetAddr& aAddr, TInt aPort, TInt aSize, TBool aMode); |
|
37 ~CTcpProcess(); |
|
38 |
|
39 private: |
|
40 CTcpProcess(CConsoleBase& aConsole, TInetAddr& aAddr, TInt aPort, TInt aSize, TBool aMode); |
|
41 void ConstructL(); |
|
42 |
|
43 void RecvDataL(); |
|
44 TInt SendDataL(TDes8& aData, TInt aSize); |
|
45 void PrintData(TDes8& aData); |
|
46 |
|
47 private: |
|
48 //From CActive |
|
49 virtual void RunL(); |
|
50 virtual void DoCancel(); |
|
51 TInt RunError(TInt aError); |
|
52 |
|
53 private: |
|
54 enum TProcessState |
|
55 { |
|
56 ECreateConnection, //Create tcp connection |
|
57 EDataTransfer //Data transfer |
|
58 }; |
|
59 |
|
60 private: |
|
61 CConsoleBase& iConsole; |
|
62 |
|
63 RSocketServ iSockServ; |
|
64 RSocket iListenSocket; |
|
65 RSocket iSocket; |
|
66 |
|
67 TInetAddr& iAddr; |
|
68 TInt iPort; |
|
69 |
|
70 //The size of send buf and receive buf |
|
71 TInt iSize; |
|
72 |
|
73 RBuf8 iRecvBuf; |
|
74 RBuf8 iSendBuf; |
|
75 |
|
76 TSockXfrLength iRecvSize; |
|
77 |
|
78 TBool iMode; //ETrue: as a Server, and data transfer is receive first, then send back |
|
79 //EFalse: as a client, and data transfer is send first, then receive. |
|
80 |
|
81 TProcessState iProcessState; |
|
82 |
|
83 }; |
|
84 |
|
85 |
|
86 class CUdpProcess : public CActive |
|
87 /** |
|
88 Run TCP test: Create a udp connection and make data transfer on it. |
|
89 */ |
|
90 { |
|
91 public: |
|
92 static CUdpProcess* NewL(CConsoleBase& aConsole, TInetAddr& aAddr, TInt aPort, TInt aSize, TBool aMode); |
|
93 ~CUdpProcess(); |
|
94 |
|
95 private: |
|
96 CUdpProcess(CConsoleBase& aConsole, TInetAddr& aAddr, TInt aPort, TInt aSize, TBool aMode); |
|
97 void ConstructL(); |
|
98 |
|
99 void RecvDataL(); |
|
100 TInt SendDataL(TDes8& aData, TInetAddr& aAddr, TInt aSize); |
|
101 void PrintData(TDes8& aData); |
|
102 |
|
103 private: |
|
104 //From CActive |
|
105 virtual void RunL(); |
|
106 virtual void DoCancel(); |
|
107 TInt RunError(TInt aError); |
|
108 |
|
109 private: |
|
110 enum TProcessState |
|
111 { |
|
112 EDataSending, //Data Sending |
|
113 EDataTransfer //Data Recving |
|
114 }; |
|
115 |
|
116 private: |
|
117 CConsoleBase& iConsole; |
|
118 |
|
119 RSocketServ iSockServ; |
|
120 RSocket iListenSocket; |
|
121 RSocket iSocket; |
|
122 |
|
123 TInetAddr iAddr; |
|
124 TInetAddr iPeerAddr; |
|
125 TInt iPort; |
|
126 |
|
127 //The size of send buf and receive buf |
|
128 TInt iSize; |
|
129 |
|
130 RBuf8 iRecvBuf; |
|
131 RBuf8 iSendBuf; |
|
132 |
|
133 TSockXfrLength iRecvSize; |
|
134 |
|
135 TBool iMode; //ETrue: as a Server, and data transfer is receive first, then send back |
|
136 //EFalse: as a client, and data transfer is send first, then receive. |
|
137 |
|
138 TProcessState iProcessState; |
|
139 |
|
140 }; |
|
141 |
|
142 |
|
143 class CTcpCommand; |
|
144 class CTcpTestConsole : public CActive |
|
145 /** |
|
146 The console of tcp test. |
|
147 */ |
|
148 { |
|
149 public: |
|
150 static CTcpTestConsole* NewL(TBool aIsTcp, TBool aMode, TDesC& aDefautAddr, TInt aIndex, CTcpCommand& aOwner); |
|
151 ~CTcpTestConsole(); |
|
152 |
|
153 TBool StartL(); |
|
154 void Help(); |
|
155 |
|
156 private: |
|
157 CTcpTestConsole(TBool aIsTcp, TBool aMode, TDesC& aDefautAddr, TInt aIndex, CTcpCommand& aOwner); |
|
158 void ConstructL(); |
|
159 |
|
160 private: |
|
161 //From CActive |
|
162 virtual void RunL(); |
|
163 virtual void DoCancel(); |
|
164 TInt RunError(TInt aError); |
|
165 |
|
166 private: |
|
167 enum TCommandMode |
|
168 { |
|
169 ECommandInit, //Get parameter from user input |
|
170 ECommandRunning //tcp test run |
|
171 }; |
|
172 |
|
173 private: |
|
174 CConsoleBase* iConsole; |
|
175 RBuf iChars; |
|
176 TCommandMode iCommandMode; |
|
177 |
|
178 CTcpProcess* iTcp; |
|
179 CUdpProcess* iUdp; |
|
180 TBool iMode; //ETrue server EFalse client |
|
181 TBool iIsTcp; |
|
182 |
|
183 //The defaut addr, format like 'addr port' (192.168.2.101 5000) |
|
184 const TDesC& iDefaultAddr; |
|
185 TInt iIndex; |
|
186 CTcpCommand& iOwner; |
|
187 |
|
188 }; |
|
189 |
|
190 #endif //TCPTEST_H |
|