|
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 #ifndef __CSOCKETWRITER_H__ |
|
17 #define __CSOCKETWRITER_H__ |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <http/framework/logging.h> |
|
21 |
|
22 #include "moutputstream.h" |
|
23 #include "mhttptimerobserver.h" |
|
24 #include "chttptimer.h" |
|
25 |
|
26 class CSocket; |
|
27 class MOutputSocketObserver; |
|
28 class MSocketController; |
|
29 |
|
30 class CSocketWriter : public CActive, |
|
31 public MOutputStream, |
|
32 public MHttpTimerObserver |
|
33 /** |
|
34 The CSocketWriter class encapsulates the writing functionality and behaviour |
|
35 for a connected socket. It implements the MOutputStream API. |
|
36 @see MOutputStream |
|
37 @internalComponent |
|
38 */ |
|
39 { |
|
40 public: // methods |
|
41 |
|
42 static CSocketWriter* NewL(CSocket& aSocket, MSocketController& aController, TBool aPriority); |
|
43 |
|
44 virtual ~CSocketWriter(); |
|
45 |
|
46 void SocketClosed(TInt aError); |
|
47 |
|
48 virtual void SecureClientReq(const TDesC8& aHostName); |
|
49 |
|
50 private: // methods from MOutputStream |
|
51 |
|
52 virtual void Bind(MOutputStreamObserver& aObserver); |
|
53 |
|
54 virtual void SendDataReqL(const TDesC8& aBuffer); |
|
55 |
|
56 virtual void ShutdownReq(); |
|
57 |
|
58 virtual void Close(); |
|
59 |
|
60 virtual const CX509Certificate* ServerCert(); |
|
61 |
|
62 virtual TInt CipherSuite(TDes8& aCipherSuite); |
|
63 |
|
64 virtual void MOutputStream_Reserved(); |
|
65 |
|
66 virtual void Reset(); |
|
67 |
|
68 virtual void SetTCPCorking(TBool aValue); |
|
69 |
|
70 void CompleteSelf(); |
|
71 |
|
72 private: // methods from CActive |
|
73 |
|
74 |
|
75 virtual void RunL(); |
|
76 |
|
77 virtual void DoCancel(); |
|
78 |
|
79 virtual TInt RunError(TInt aError); |
|
80 |
|
81 private: // methods from MHttpTimerObserver |
|
82 |
|
83 virtual void TimeOut(); |
|
84 |
|
85 private: // methods |
|
86 |
|
87 CSocketWriter(CSocket& aSocket, MSocketController& aController, TBool aPriority); |
|
88 |
|
89 private: // enums |
|
90 |
|
91 /** |
|
92 The state machine for the output stream. |
|
93 @internalComponent |
|
94 */ |
|
95 enum TOutputState |
|
96 { |
|
97 /** The output stream is waiting for an observer to bind itself to it. |
|
98 */ |
|
99 EIdle = 0, |
|
100 /** The output stream is ready to send data to the socket. It is waiting |
|
101 for the observer to request a data send. |
|
102 */ |
|
103 EPendingSend, |
|
104 /** Data has been sent to the socket. The output stream is waiting for |
|
105 the socket to notify it that the write was successful. |
|
106 */ |
|
107 ESentData, |
|
108 /** The observer has requested that the connection be upgraded to secure. |
|
109 Need to start the secure handshake. |
|
110 */ |
|
111 EStartSecureHandshake, |
|
112 /** The secure handshake has completed successfully. Inform the observer |
|
113 that the connection is now secure. |
|
114 */ |
|
115 ESecureHandshakeComplete, |
|
116 /** The observer has asked the output stream to close the socket. |
|
117 */ |
|
118 EClosing, |
|
119 /** The socket has been closed - data can no longer be sent to it. |
|
120 */ |
|
121 EClosed |
|
122 }; |
|
123 |
|
124 private: // attributes |
|
125 |
|
126 /** The connected socket. |
|
127 */ |
|
128 CSocket& iSocket; |
|
129 |
|
130 /** The socket controller that owns the socket. |
|
131 */ |
|
132 MSocketController& iController; |
|
133 |
|
134 /** The state of the output stream. |
|
135 */ |
|
136 TOutputState iState; |
|
137 |
|
138 /** The observer for the output stream. |
|
139 */ |
|
140 MOutputStreamObserver* iObserver; |
|
141 |
|
142 //CHttpTimer Object |
|
143 CHttpTimer* iSendTimer; |
|
144 |
|
145 TPtrC8 iHostName; |
|
146 |
|
147 public: // attributes |
|
148 |
|
149 /** Logger handle |
|
150 */ |
|
151 __FLOG_DECLARATION_MEMBER2 |
|
152 |
|
153 }; |
|
154 |
|
155 #endif // __CSOCKETWRITER_H__ |