|
1 /* |
|
2 * Copyright (c) 2006 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: CSocketsRead is an active obejct that reads data from |
|
15 * an already open socket and calculates some metrics from the data read |
|
16 * |
|
17 */ |
|
18 |
|
19 #ifndef __SOCKETSREAD_H__ |
|
20 #define __SOCKETSREAD_H__ |
|
21 |
|
22 #include <in_sock.h> |
|
23 #include "conntest.hrh" |
|
24 |
|
25 // CONSTANTS |
|
26 |
|
27 const TInt KMaximumPacketCount = 4000; // Count to 4000. Fails if ploss is over 20% (1000pckts) |
|
28 |
|
29 // FORWARD DECLARATIONS |
|
30 class MUINotify; |
|
31 class CSocketsEngine; |
|
32 |
|
33 // CLASS DECLARATION |
|
34 |
|
35 /** |
|
36 * This class handles reading data from the socket. |
|
37 * In this implementation, any data read is simply |
|
38 * displayed as text on the console. |
|
39 */ |
|
40 class CSocketsRead : public CActive |
|
41 { |
|
42 public: |
|
43 |
|
44 /** |
|
45 * Create a CSocketsRead object |
|
46 * @param aConsole console to use for ui output |
|
47 * @param aSocket socket to read from |
|
48 * @result a pointer to the created instance of CSocketsRead |
|
49 */ |
|
50 static CSocketsRead* NewL(MUINotify& aConsole, RSocket& aSocket, CSocketsEngine& aEngine); |
|
51 |
|
52 /** |
|
53 * Create a CSocketsRead object |
|
54 * @param aConsole console to use for ui output |
|
55 * @param aSocket socket to read from |
|
56 * @result a pointer to the created instance of CSocketsRead |
|
57 */ |
|
58 static CSocketsRead* NewLC(MUINotify& aConsole, RSocket& aSocket, CSocketsEngine& aEngine); |
|
59 |
|
60 /** |
|
61 * Destroy the object and release all memory objects |
|
62 */ |
|
63 ~CSocketsRead(); |
|
64 |
|
65 /** |
|
66 * Initiate the read process. |
|
67 * @param aAddress Address where data is sent (needed by UDP) |
|
68 * @param aProtocol Protocol to be used (TCP or UDP) |
|
69 */ |
|
70 void Start(TInetAddr* aAddress, TUint aProtocol); |
|
71 |
|
72 /** |
|
73 * Set throughput calculation on or off. |
|
74 * @param aValue If ETrue, measure throughput |
|
75 */ |
|
76 void SetPerformance(const TBool aValue); |
|
77 |
|
78 /** |
|
79 * Start RAW read |
|
80 */ |
|
81 void StartRAWRead(TInetAddr* aAddress, TUint aProtocol); |
|
82 |
|
83 protected: // from CActive |
|
84 |
|
85 /** |
|
86 * Cancel any outstanding operation |
|
87 */ |
|
88 void DoCancel(); |
|
89 |
|
90 /** |
|
91 * Called when operation complete |
|
92 */ |
|
93 void RunL(); |
|
94 |
|
95 private: |
|
96 |
|
97 /** |
|
98 * Perform the first phase of two phase construction |
|
99 * @param aConsole console to use for ui output |
|
100 * @param aSocket socket to read from |
|
101 */ |
|
102 CSocketsRead(MUINotify& aConsole, RSocket& aSocket, CSocketsEngine& aEngine); |
|
103 |
|
104 /** |
|
105 * Perform the second phase construction of a CSocketsRead |
|
106 */ |
|
107 void ConstructL(); |
|
108 |
|
109 /** |
|
110 * Read data from socket |
|
111 */ |
|
112 void IssueRead(); |
|
113 |
|
114 /** |
|
115 * Calculate packet loss |
|
116 * @return ploss percentage |
|
117 */ |
|
118 TInt32 CalculatePacketLoss(); |
|
119 |
|
120 private: // Member variables |
|
121 // enum { KReadBufferSize = 4096 }; // 4K |
|
122 //enum { KReadBufferSize = 10240 }; // 10K |
|
123 // Member variables |
|
124 CSocketsEngine& iEngine; // connection engine |
|
125 RSocket& iSocket; // socket to read data from |
|
126 MUINotify& iConsole; // console for displaying text etc |
|
127 TBuf8<KReadDataSize> iBuffer; // buffer for receiving data |
|
128 TSockXfrLength iDummyLength; // dummy - length of data read is written here |
|
129 TInt iReceivedBytes; |
|
130 TInt32 iUdpPacketCounter; |
|
131 TBool iDoCount; |
|
132 TBool iDoPerformance; |
|
133 TInetAddr* iAddress; |
|
134 TUint iProtocol; |
|
135 TTime iStartTime; |
|
136 TBuf8<2048> iHeaders; // buffer for HTTP headers |
|
137 TInt iBodySize; |
|
138 }; |
|
139 |
|
140 #endif // __SOCKETSREAD_H__ |
|
141 |