|
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: CSocketsWrite is an active object which implements data |
|
15 * sending through an already open socket using UDP or TCP |
|
16 * |
|
17 */ |
|
18 |
|
19 #ifndef __SOCKETSWRITE_H__ |
|
20 #define __SOCKETSWRITE_H__ |
|
21 |
|
22 #include <in_sock.h> |
|
23 #include "TimeOutNotify.h" |
|
24 #include "conntest.hrh" |
|
25 |
|
26 // FORWARD DECLARATIONS |
|
27 class CTimeOutTimer; |
|
28 class MUINotify; |
|
29 class MDataSendNotifyHandler; |
|
30 |
|
31 // CLASS DECLARATION |
|
32 |
|
33 /** |
|
34 * This class handles writing data to the socket. |
|
35 * Data to be written is accumulated in iTransferBuffer, |
|
36 * and is then transferred to iWriteBuffer for the actual |
|
37 * write to the socket. |
|
38 */ |
|
39 class CSocketsWrite : public CActive, public MTimeOutNotify |
|
40 { |
|
41 public: |
|
42 |
|
43 /** |
|
44 * Create a CSocketsWrite object |
|
45 * @param aConsole console to use for ui output |
|
46 * @param aSocket socket to write to |
|
47 * @param aSendHandler handler to notify UDP packet sends |
|
48 * @result a pointer to the created instance of CSocketsWrite |
|
49 */ |
|
50 static CSocketsWrite* NewL( MUINotify& aConsole, |
|
51 RSocket& aSocket, |
|
52 MDataSendNotifyHandler& aSendHandler ); |
|
53 |
|
54 /** |
|
55 * Create a CSocketsWrite object |
|
56 * @param aConsole console to use for ui output |
|
57 * @param aSocket socket to write to |
|
58 * @param aSendHandler handler to notify UDP packet sends |
|
59 * @result a pointer to the created instance of CSocketsWrite |
|
60 */ |
|
61 static CSocketsWrite* NewLC( MUINotify& aConsole, |
|
62 RSocket& aSocket, |
|
63 MDataSendNotifyHandler& aSendHandler ); |
|
64 |
|
65 /** |
|
66 * Destroy the object and release all memory objects |
|
67 */ |
|
68 ~CSocketsWrite(); |
|
69 |
|
70 /** |
|
71 * Write the data to the socket (buffered) |
|
72 * @param aData the data to be written |
|
73 * @param aAddress Address where data is sent (needed by UDP) |
|
74 * @param aProtocol Protocol to be used (TCP or UDP) |
|
75 */ |
|
76 void IssueWriteL(const TDesC8& aData, TInetAddr* aAddress, TUint aProtocol); |
|
77 |
|
78 /** |
|
79 * Write the data to the socket flooded |
|
80 * @param aData the data to be written |
|
81 * @param aAddress Address where data is sent (needed by UDP) |
|
82 * @param aProtocol Protocol to be used (TCP or UDP) |
|
83 * @param aCount The packet will be sent aCount times |
|
84 */ |
|
85 void IssueWriteL(const TDesC8& aData, TInetAddr* aAddress, TUint aProtocol, TInt aCount); |
|
86 |
|
87 /** |
|
88 * Write the data to the socket (buffered) |
|
89 * @param aData the data to be written |
|
90 * @param aAddress Address where data is sent (needed by UDP) |
|
91 * @param aProtocol Protocol to be used (TCP or UDP) |
|
92 */ |
|
93 void IssueWriteL( const TDesC8& aData, |
|
94 TInetAddr* aAddress, |
|
95 TUint aProtocol, |
|
96 TInt aPacketSize, |
|
97 TInt aPackets ); |
|
98 |
|
99 protected: // from CActive |
|
100 |
|
101 /** |
|
102 * Cancel any outstanding operation |
|
103 */ |
|
104 void DoCancel(); |
|
105 |
|
106 /** |
|
107 * Called when operation complete |
|
108 */ |
|
109 void RunL(); |
|
110 |
|
111 // From MTimeOutNotify |
|
112 void TimerExpired(); |
|
113 |
|
114 private: |
|
115 |
|
116 /** |
|
117 * Perform the first phase of two phase construction |
|
118 * @param aConsole console to use for ui output |
|
119 * @param aSocket socket to write to |
|
120 * @param aSendHandler handler to notify UDP packet sends |
|
121 */ |
|
122 CSocketsWrite( MUINotify& aConsole, |
|
123 RSocket& aSocket, |
|
124 MDataSendNotifyHandler& aSendHandler ); |
|
125 |
|
126 /** |
|
127 * Perform the second phase construction of a CSocketsWrite |
|
128 */ |
|
129 void ConstructL(); |
|
130 |
|
131 /** |
|
132 * Handle a 'write buffer empty' situation. |
|
133 */ |
|
134 void SendNextPacket(); |
|
135 |
|
136 /** |
|
137 * Calls the actual write when flooding |
|
138 */ |
|
139 void DoFloodWrite(); |
|
140 |
|
141 |
|
142 private: // Member data |
|
143 enum TWriteState |
|
144 { |
|
145 ESending, EWaiting ,ECommsFailed |
|
146 }; |
|
147 |
|
148 |
|
149 // Member variables |
|
150 RSocket& iSocket; |
|
151 MUINotify& iConsole; // console for displaying text etc |
|
152 //TBuf8<KMaxSendBuffer> iTransferBuffer; // Accumulate data to send in here |
|
153 //TBuf8<KMaxSendBuffer> iWriteBuffer; // Holds data currently being sent to socket |
|
154 HBufC8* iTransferBuffer; |
|
155 HBufC8* iWriteBuffer; |
|
156 CTimeOutTimer* iTimer; |
|
157 TInt iTimeOut; |
|
158 TWriteState iWriteStatus; |
|
159 TInetAddr* iAddress; |
|
160 TUint iProtocol; |
|
161 TInt iPackets; |
|
162 TInt iPacketSize; |
|
163 TInt iSentBytes; |
|
164 TTime iStartTime; |
|
165 TInt iDataChunkCount; |
|
166 HBufC8* iReqBodySubmitBuffer; |
|
167 TPtr8 iReqBodySubmitBufferPtr; |
|
168 MDataSendNotifyHandler& iSendHandler; |
|
169 TBool iFlood; // Flood mode sending |
|
170 TInt iCount; // Times to flood the packet |
|
171 }; |
|
172 |
|
173 #endif // __SOCKETSWRITE_H__ |
|
174 |