|
1 /** @file |
|
2 * Copyright (c) 2005-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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "upnptcpsession.h" |
|
21 #include "upnpretrywrite.h" |
|
22 |
|
23 #ifdef _DEBUG |
|
24 #define KLogFile _L("DLNAWebServer.txt") |
|
25 #endif |
|
26 #include "upnpcustomlog.h" |
|
27 |
|
28 // ----------------------------------------------------------------------------- |
|
29 // CUpnpRetryWrite::NewL |
|
30 // |
|
31 // ----------------------------------------------------------------------------- |
|
32 // |
|
33 CUpnpRetryWrite* CUpnpRetryWrite::NewL( CUpnpTcpSession& aSession, RSocket& aSocket, MUpnpRetryWriteObserver* aObserver, TThreadPriority aPriority ) |
|
34 { |
|
35 CUpnpRetryWrite* self = new ( ELeave ) CUpnpRetryWrite( aSession, aSocket, aObserver, aPriority ); |
|
36 CleanupStack::PushL( self ); |
|
37 self->ConstructL(); |
|
38 CleanupStack::Pop( self ); |
|
39 return self; |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CUpnpRetryWrite::CUpnpRetryWrite |
|
44 // |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 CUpnpRetryWrite::CUpnpRetryWrite( CUpnpTcpSession& aSession, RSocket& aSocket, MUpnpRetryWriteObserver* aObserver, TThreadPriority aPriority ):CActive( aPriority ),iSession( aSession ),iSocket( aSocket ),iObserver( aObserver ),iInternalState(EUnknown),iWriteErrorsCount(0) |
|
48 { |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CUpnpRetryWrite::ConstructL |
|
53 // |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 void CUpnpRetryWrite::ConstructL() |
|
57 { |
|
58 CActiveScheduler::Add( this ); |
|
59 User::LeaveIfError( iWriteTimer.CreateLocal() ); |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CUpnpRetryWrite::~CUpnpRetryWrite |
|
64 // |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 CUpnpRetryWrite::~CUpnpRetryWrite() |
|
68 { |
|
69 Cancel(); |
|
70 iWriteTimer.Close(); |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CUpnpRetryWrite::IssueWriteRetry |
|
75 // |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 void CUpnpRetryWrite::IssueWriteRetry() |
|
79 { |
|
80 iSession.WaitRetryError(iStatus.Int()); |
|
81 iWriteTimer.After( iStatus, KWaitWithSocketWrite * ++iWriteErrorsCount ); |
|
82 SetActive(); |
|
83 iInternalState = EWaiting; |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CUpnpRetryWrite::WriteToSocket |
|
88 // |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 void CUpnpRetryWrite::WriteToSocket() |
|
92 { |
|
93 iSession.WaitRetryError(iStatus.Int(), ETrue); |
|
94 iSocket.Write( KNullDesC8, iStatus ); |
|
95 SetActive(); |
|
96 iInternalState = EWriting; |
|
97 } |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // CUpnpRetryWrite::PassErrorToObserverL |
|
101 // |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 void CUpnpRetryWrite::PassErrorToObserverL( TInt aError ) |
|
105 { |
|
106 iInternalState = EUnknown; |
|
107 iWriteErrorsCount = 0; |
|
108 iObserver->RetryWriteFailL( aError ); |
|
109 } |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // CUpnpRetryWrite::RunL |
|
113 // |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 void CUpnpRetryWrite::RunL() |
|
117 { |
|
118 if ( iStatus == KErrNone ) |
|
119 { |
|
120 switch( iInternalState ) |
|
121 { |
|
122 case EWaiting: |
|
123 WriteToSocket(); |
|
124 break; |
|
125 case EWriting: |
|
126 iInternalState = EUnknown; |
|
127 iWriteErrorsCount = 0; |
|
128 iObserver->RetryWriteSucceed(); |
|
129 break; |
|
130 } |
|
131 } |
|
132 else |
|
133 { |
|
134 if( iInternalState == EWriting ) |
|
135 { |
|
136 switch( iStatus.Int() ) |
|
137 { |
|
138 case KErrNoMemory: |
|
139 case KErrNotReady: |
|
140 if( iWriteErrorsCount < KWriteErrorsMax ) |
|
141 { |
|
142 IssueWriteRetry(); |
|
143 break; |
|
144 } |
|
145 default: |
|
146 PassErrorToObserverL( iStatus.Int() ); |
|
147 break; |
|
148 } |
|
149 } |
|
150 else |
|
151 { |
|
152 if( iInternalState == EWaiting && iStatus.Int() == KErrAbort ) |
|
153 { |
|
154 iWriteTimer.After(iStatus,1); |
|
155 iWriteErrorsCount++; |
|
156 SetActive(); |
|
157 } |
|
158 else |
|
159 PassErrorToObserverL( iStatus.Int() ); |
|
160 } |
|
161 } |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // CUpnpRetryWrite::DoCancel |
|
166 // |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 void CUpnpRetryWrite::DoCancel() |
|
170 { |
|
171 iWriteErrorsCount = 0; |
|
172 iInternalState = EUnknown; |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // CUpnpRetryWrite::RunError |
|
177 // |
|
178 // ----------------------------------------------------------------------------- |
|
179 // |
|
180 TInt CUpnpRetryWrite::RunError( TInt aError ) |
|
181 { |
|
182 LOGS1("CUpnpRetryWrite::RunError(%d)", aError); |
|
183 return KErrNone; |
|
184 } |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // CUpnpRetryWrite::IsStarted |
|
188 // |
|
189 // ----------------------------------------------------------------------------- |
|
190 // |
|
191 TBool CUpnpRetryWrite::IsStarted() |
|
192 { |
|
193 return (iInternalState != EUnknown); |
|
194 } |
|
195 |