|
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: Declares ControlPoint class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "upnptcpsessionreader.h" |
|
22 #include "upnphttpfiletransferreader.h" |
|
23 #include "upnphttpchunkfiletransferreader.h" |
|
24 #include "upnphttpfiletransferwriter.h" |
|
25 #include "upnptcpsessionwriter.h" |
|
26 #include "upnphttpsession.h" |
|
27 #include "upnphttpfileaccess.h" |
|
28 #include "upnphttpmessagefactory.h" |
|
29 #include "upnphttpbuffer.h" |
|
30 #define KLogFile _L("DLNAWebServer.txt") |
|
31 #include "upnpcustomlog.h" |
|
32 |
|
33 //CONSTANTS |
|
34 const TInt KMaxExportRetry = 0; |
|
35 |
|
36 // ============================ MEMBER FUNCTIONS =============================== |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // CUpnpTcpSession::CUpnpTcpSession |
|
40 // C++ constructor used when remote host issued connection to server |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 CUpnpTcpSession::CUpnpTcpSession( RSocket& aSocket, |
|
44 TThreadPriority aPriority ) |
|
45 : iSocket( aSocket ), |
|
46 iTimeoutCurrentValue( KSessionTimeout ), iTimeoutSessionValue(KSessionTimeout) |
|
47 { |
|
48 iInitialPriority = aPriority; |
|
49 |
|
50 iSessionNeedsErrorReply = ETrue; |
|
51 iDisconnectNotification=ETrue; |
|
52 iContinuedMessageDownload = EFalse; |
|
53 iExportRetryCounter = 0; |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CUpnpTcpSession::TcpConstructL |
|
58 // Two-phased constructor |
|
59 // constructor that can leave. Used from derived classes. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 void CUpnpTcpSession::TcpConstructL( RSocket aSocket, |
|
63 TInt aReadBufferSize, |
|
64 TInt aFileReadBufferSize ) |
|
65 { |
|
66 |
|
67 LOGS1( "%i, CUpnpTcpSession::TcpConstructL(RSocket)", iId ); |
|
68 |
|
69 aSocket.RemoteName( iAddr ); |
|
70 iAddr.ConvertToV4(); |
|
71 |
|
72 // Create timeout timer and start it. |
|
73 iTimeoutTimer = CUpnpNotifyTimer::NewL( this ); |
|
74 iSocketShutdown = CUpnpSocketShutdown::NewL( *this, iSocket, iInitialPriority ); |
|
75 |
|
76 // Create socket read and write active objects |
|
77 iTcpReader = CUpnpTcpSessionReader::NewL( *this, iSocket, |
|
78 iInitialPriority, aReadBufferSize ); |
|
79 iTcpWriter = CUpnpTcpSessionWriter::NewL( *this, iSocket, iInitialPriority ); |
|
80 |
|
81 iDisconnectNotification = ETrue; |
|
82 iIsPersistent = ETrue; |
|
83 iFileReadBufferSize = aFileReadBufferSize; |
|
84 |
|
85 SetState( EConnected ); |
|
86 |
|
87 InitialReceiveL(); |
|
88 |
|
89 StartTimeoutTimer( iSessionNeedsErrorReply ); |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // CUpnpTcpSession::FileTransferReaderConstructL |
|
94 // Creates and activates the File Transfer reder object |
|
95 // constructor that can leave. Used from derived classes. |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 void CUpnpTcpSession::FileTransferReaderConstructL() |
|
99 { |
|
100 LOGS1( "%i, CUpnpTcpSession::FileTransferConstructL", iId ); |
|
101 |
|
102 // Create filetransfer reader, active object |
|
103 if(!iFTReader) |
|
104 { |
|
105 if(this->FileAccess() && this->FileAccess()->EncodingMode()) |
|
106 { |
|
107 iFTReader = CUpnpHttpChunkFileTransferReader::NewL( *this, iSocket, |
|
108 iInitialPriority, KFileTransferReaderBufSizeDefault, |
|
109 CUpnpHttpChunkFileTransferReader::CalculateBufferSize( |
|
110 KFileTransferReaderBufSizeDefault,iFileReadBufferSize)); |
|
111 } |
|
112 else |
|
113 { |
|
114 iFTReader = CUpnpHttpFileTransferReader::NewL( *this, iSocket, |
|
115 iInitialPriority, KFileTransferReaderBufSizeDefault, |
|
116 CUpnpHttpChunkFileTransferReader::CalculateBufferSize( |
|
117 KFileTransferReaderBufSizeDefault,iFileReadBufferSize)); |
|
118 } |
|
119 } |
|
120 else |
|
121 iFTReader->Reset(); |
|
122 |
|
123 iFTReader->SetActivated(ETrue); |
|
124 |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CUpnpTcpSession::FileTransferWriterConstructL |
|
129 // Creates and activates the File Transfer writer object |
|
130 // constructor that can leave. Used from derived classes. |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 void CUpnpTcpSession::FileTransferWriterConstructL(TInt aWriteSize) |
|
134 { |
|
135 LOGS1( "%i, CUpnpTcpSession::FileTransferWriterConstructL", iId ); |
|
136 |
|
137 // Create filetransfer writer, active object |
|
138 if (!iFTWriter) |
|
139 { |
|
140 iFTWriter = CUpnpHttpFileTransferWriter::NewL( *this, iSocket, |
|
141 iInitialPriority, aWriteSize); |
|
142 } |
|
143 else |
|
144 iFTWriter->Reset(); |
|
145 |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CUpnpTcpSession::~CUpnpTcpSession |
|
150 // C++ default destructor. |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 CUpnpTcpSession::~CUpnpTcpSession() |
|
154 { |
|
155 delete iTcpReader; |
|
156 delete iTcpWriter; |
|
157 delete iFTReader; |
|
158 if(iFTWriter) |
|
159 { |
|
160 if(iState != ENotConnected) |
|
161 { |
|
162 iSocket.CancelWrite(); |
|
163 } |
|
164 delete iFTWriter; |
|
165 } |
|
166 |
|
167 delete iTimeoutTimer; |
|
168 delete iReceivedMessage; |
|
169 delete iSocketShutdown; |
|
170 LOGS2( "%i, CUpnpTcpSession::~CUpnpTcpSession() - iState: %i",iId, iState ); |
|
171 } |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CUpnpTcpSession::ShutdownStop |
|
175 // Disconnect connection |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 void CUpnpTcpSession::ShutdownStop() |
|
179 { |
|
180 LOGS2( "%i, CUpnpTcpSession::ShutdownStop, state %i", iId, iState ); |
|
181 iState = EShuttingDownWriteWait; |
|
182 if( !iTcpWriter->IsWriting() && !iTcpWriter->IsRetrying() ) |
|
183 { |
|
184 iSocketShutdown->ShutdownStop(); |
|
185 SetState( EShuttingDown); |
|
186 } |
|
187 |
|
188 } |
|
189 |
|
190 // ----------------------------------------------------------------------------- |
|
191 // CUpnpTcpSession::WriteL |
|
192 // Write |
|
193 // ----------------------------------------------------------------------------- |
|
194 // |
|
195 void CUpnpTcpSession::WriteL( const TDesC8& aBuffer ) |
|
196 { |
|
197 LOGS1( "%i, CUpnpTcpSession::WriteL(TDesC8&)", iId ); |
|
198 |
|
199 iTcpWriter->IssueWriteL( aBuffer ); |
|
200 |
|
201 StartTimeoutTimer( iContinuedMessageDownload ); |
|
202 |
|
203 LOGS2( "%i, CUpnpTcpSession::WriteL - HTTP (Serverport %i) *** Writing...", |
|
204 iId, ServerPort() ); |
|
205 } |
|
206 |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // CUpnpTcpSession::InitialReceiveL |
|
210 // Receive |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 void CUpnpTcpSession::InitialReceiveL() |
|
214 { |
|
215 LOGS1( "%i, CUpnpTcpSession::ReceiveL()", iId ); |
|
216 if ( ( iState == EConnected ) && ( !iTcpReader->IsActive() ) ) |
|
217 { |
|
218 iTcpReader->Start(); |
|
219 } |
|
220 } |
|
221 |
|
222 // ----------------------------------------------------------------------------- |
|
223 // CUpnpTcpSession::ReceiveL |
|
224 // Receive |
|
225 // ----------------------------------------------------------------------------- |
|
226 // |
|
227 void CUpnpTcpSession::ReceiveL() |
|
228 { |
|
229 // If session is already close or it will be closed when reading is finisihed |
|
230 if ( IsConnected() && ( iSessionKeepAlive || DownloadOngoing() ) ) |
|
231 { |
|
232 if (iFTReader && iFTReader->Activated()) |
|
233 { |
|
234 iFTReader->StartL(); |
|
235 } |
|
236 else |
|
237 { |
|
238 iTcpReader->Start(); |
|
239 } |
|
240 StartTimeoutTimer( iSessionNeedsErrorReply ); |
|
241 } |
|
242 else if ( OutstandingWritings() ) //outstanding TCP writing operations |
|
243 { |
|
244 StartTimeoutTimer( iSessionNeedsErrorReply ); |
|
245 } |
|
246 else |
|
247 { |
|
248 StartDisconnect(); |
|
249 } |
|
250 } |
|
251 |
|
252 |
|
253 // ----------------------------------------------------------------------------- |
|
254 // CUpnpTcpSession::ReceivingCompletedL |
|
255 // |
|
256 // ----------------------------------------------------------------------------- |
|
257 // |
|
258 void CUpnpTcpSession::ReceivingCompletedL( TDesC8& aBuffer ) |
|
259 { |
|
260 LOGS1( "%i, CUpnpTcpSession::ReceivingCompletedL(TDesC8& aBuffer)", iId); |
|
261 |
|
262 iTimeoutTimer->Cancel(); |
|
263 BufferReceivedL( aBuffer ); |
|
264 ReceiveL(); |
|
265 } |
|
266 |
|
267 // ----------------------------------------------------------------------------- |
|
268 // CUpnpTcpSession::WritingCompletedL |
|
269 // |
|
270 // ----------------------------------------------------------------------------- |
|
271 // |
|
272 void CUpnpTcpSession::WritingCompletedL() |
|
273 { |
|
274 LOGS2( "%i, CUpnpTcpSession::WritingCompletedL() iState %i", iId, iState ); |
|
275 |
|
276 iTimeoutTimer->Cancel(); |
|
277 |
|
278 switch( iState ) |
|
279 { |
|
280 case EConnected: |
|
281 { |
|
282 TInetAddr local; |
|
283 iSocket.LocalName( local ); |
|
284 local.SetFamily( KAfInet ); |
|
285 |
|
286 TInetAddr remote; |
|
287 iSocket.RemoteName( remote ); |
|
288 remote.SetFamily( KAfInet ); |
|
289 |
|
290 if( ( iSessionKeepAlive || remote == local ) && !iContinuedMessageDownload ) |
|
291 { |
|
292 // 20s timeout without HTTP 408 message |
|
293 StartTimeoutTimer( EFalse ); |
|
294 } |
|
295 else if( iContinuedMessageDownload ) |
|
296 { |
|
297 // If there is expected content of the POST message after sending |
|
298 // there should be error response after timeout. |
|
299 // 20s timeout with HTTP 408 message |
|
300 StartTimeoutTimer( ETrue ); |
|
301 } |
|
302 else |
|
303 { |
|
304 //if no POSTs left in a pipeline |
|
305 if (!iSessionKeepAlive) |
|
306 { |
|
307 iSessionNeedsErrorReply = EFalse; |
|
308 StartDisconnect(); |
|
309 } |
|
310 } |
|
311 } |
|
312 |
|
313 break; |
|
314 case EShuttingDownWriteWait: |
|
315 //after successful writing continue to shutdown |
|
316 ShutdownStop(); |
|
317 break; |
|
318 case EDisconnecting: |
|
319 if ( iDisconnectNotification ) |
|
320 { |
|
321 NotifyDisconnectL( RemoteHost() ); |
|
322 DeleteThisSessionL( this ); |
|
323 } |
|
324 else |
|
325 { |
|
326 iSessionNeedsErrorReply = EFalse; |
|
327 StartDisconnect(); |
|
328 } |
|
329 break; |
|
330 case EServerBusy: |
|
331 DeleteThisSessionL( this ); |
|
332 break; |
|
333 default: |
|
334 LOGS2( "%i, PANIC: CUpnpTcpSession::WritingCompletedL, iState: %i", iId, iState ); |
|
335 break; |
|
336 |
|
337 } |
|
338 } |
|
339 |
|
340 // ----------------------------------------------------------------------------- |
|
341 // CUpnpTcpSession::ServerBusyL |
|
342 // Send server busy. |
|
343 // ----------------------------------------------------------------------------- |
|
344 // |
|
345 void CUpnpTcpSession::ServerBusyL() |
|
346 { |
|
347 LOGS1( "%i, CUpnpTcpSession::ServerBusyL()", iId ); |
|
348 // no reason for reader to read data |
|
349 iTcpReader->Cancel(); |
|
350 if(iFTReader) |
|
351 iFTReader->Cancel(); |
|
352 |
|
353 CUpnpHttpMessage* msg = RUpnpHttpMessageFactory::HttpResponseErrorL( |
|
354 RemoteHost(), |
|
355 EHttpServiceUnavailable ); |
|
356 CleanupStack::PushL( msg ); |
|
357 HBufC8* msgbody = NULL; |
|
358 msgbody = msg->ToStringL(); |
|
359 |
|
360 CleanupStack::PopAndDestroy(msg); |
|
361 CleanupStack::PushL( msgbody ); |
|
362 |
|
363 WriteL( *msgbody ); |
|
364 CleanupStack::PopAndDestroy(msgbody); |
|
365 |
|
366 iState = EServerBusy; |
|
367 } |
|
368 |
|
369 // ----------------------------------------------------------------------------- |
|
370 // CUpnpTcpSession::Id |
|
371 // Returns session ID |
|
372 // ----------------------------------------------------------------------------- |
|
373 // |
|
374 TInt CUpnpTcpSession::Id() |
|
375 { |
|
376 return iId; |
|
377 } |
|
378 |
|
379 // ----------------------------------------------------------------------------- |
|
380 // CUpnpTcpSession::StartTimeoutTimerL |
|
381 // Start timer. |
|
382 // ----------------------------------------------------------------------------- |
|
383 // |
|
384 void CUpnpTcpSession::StartTimeoutTimer( TBool aSessionErrorReplyNeeded ) |
|
385 { |
|
386 LOGS2( "%i, CUpnpTcpSession::StartTimeoutTimer, state %i", iId, iState ); |
|
387 |
|
388 if( !ShuttingDown()) |
|
389 { |
|
390 iTimeoutTimer->Cancel(); |
|
391 iTimeoutTimer->After( iTimeoutCurrentValue, EFalse ); |
|
392 iSessionNeedsErrorReply = aSessionErrorReplyNeeded; |
|
393 LOGS2( "%i, CUpnpTcpSession::StartTimeoutTimer session:%i" |
|
394 , iId, iTimeoutCurrentValue ); |
|
395 } |
|
396 else |
|
397 { |
|
398 // If already session is switched to disconnected state then just delete it. |
|
399 LOGS1( "%i, CUpnpTcpSession::StartTimeoutTimer session disconnected" |
|
400 , iId ); |
|
401 iSessionNeedsErrorReply = EFalse; |
|
402 StartDisconnect(); |
|
403 } |
|
404 } |
|
405 |
|
406 // ----------------------------------------------------------------------------- |
|
407 // CUpnpTcpSession::StartDisconnectingTimer |
|
408 // Start timer. |
|
409 // ----------------------------------------------------------------------------- |
|
410 // |
|
411 void CUpnpTcpSession::StartDisconnectingTimer(TInt aTime) |
|
412 { |
|
413 LOGS2( "%i, CUpnpTcpSession::StartDisconnectingTimer, state %i", |
|
414 iId, iState ); |
|
415 StartDisconnect(); |
|
416 iTimeoutTimer->After( aTime, EFalse ); |
|
417 } |
|
418 |
|
419 // ----------------------------------------------------------------------------- |
|
420 // CUpnpTcpSession::StartDisconnect |
|
421 // Start disconnect session. |
|
422 // ----------------------------------------------------------------------------- |
|
423 // |
|
424 void CUpnpTcpSession::StartDisconnect(TBool aDisconnectNotification) |
|
425 { |
|
426 LOGS2( "%i, CUpnpTcpSession::StartDisconnect, state %i", |
|
427 iId, iState ); |
|
428 |
|
429 iDisconnectNotification = aDisconnectNotification; |
|
430 if( iState == EConnected ) |
|
431 SetState( EDisconnecting ); |
|
432 iTimeoutTimer->Cancel(); |
|
433 TRAPD( err, DisconnectRequestL() ); |
|
434 if( err < 0 ) |
|
435 { |
|
436 ShutdownStop(); |
|
437 } |
|
438 } |
|
439 |
|
440 // ----------------------------------------------------------------------------- |
|
441 // CUpnpTcpSession::TimerEventL |
|
442 // Timer event. |
|
443 // ----------------------------------------------------------------------------- |
|
444 // |
|
445 void CUpnpTcpSession::TimerEventL( CUpnpNotifyTimer* /*aTimer*/ ) |
|
446 { |
|
447 if( iState == EConnected ) iSocketShutdown->MarksTimeout(); |
|
448 this->DisconnectRequestL(); |
|
449 } |
|
450 |
|
451 // ----------------------------------------------------------------------------- |
|
452 // CUpnpTcpSession::DisconnectRequestL |
|
453 // Handles discnnect request. |
|
454 // ----------------------------------------------------------------------------- |
|
455 // |
|
456 void CUpnpTcpSession::DisconnectRequestL() |
|
457 { |
|
458 LOGS2( "%i, CUpnpTcpSession::DisconnectRequestL - HTTP (Serverport %i)" |
|
459 , iId, ServerPort() ); |
|
460 if (DownloadOngoing() && (iState != EDisconnecting)) |
|
461 { |
|
462 if(iExportRetryCounter < KMaxExportRetry) |
|
463 { |
|
464 //restart timer - download ongoing |
|
465 StartTimeoutTimer(ETrue); |
|
466 iExportRetryCounter++; |
|
467 } |
|
468 else |
|
469 { |
|
470 iSocket.CancelWrite(); |
|
471 SetState( ENotConnected ); |
|
472 NotifyDisconnectL( RemoteHost() ); |
|
473 iSessionNeedsErrorReply=EFalse; |
|
474 DeleteThisSessionL( this ); |
|
475 } |
|
476 return; |
|
477 } |
|
478 |
|
479 if ( iSessionNeedsErrorReply && !ShuttingDown() ) |
|
480 { |
|
481 LOGS1( "%i, CUpnpTcpSession::DisconnectRequestL - reply 408!", iId ); |
|
482 |
|
483 CUpnpHttpMessage* msg = RUpnpHttpMessageFactory::HttpResponseErrorL( |
|
484 RemoteHost(), |
|
485 EHttpRequestTimeout ); |
|
486 CleanupStack::PushL( msg ); |
|
487 HBufC8* tempBuf = NULL; |
|
488 tempBuf = msg->ToStringL(); |
|
489 CleanupStack::PopAndDestroy( msg ); |
|
490 CleanupStack::PushL( tempBuf ); |
|
491 WriteL( *tempBuf ); |
|
492 CleanupStack::PopAndDestroy( tempBuf ); |
|
493 SetState( EDisconnecting ); |
|
494 NotifyTimeoutL(); |
|
495 } |
|
496 else |
|
497 { |
|
498 LOGS1( "%i, CUpnpTcpSession::DisconnectRequestL - no reply!", iId ); |
|
499 DeleteThisSessionL( this ); |
|
500 } |
|
501 |
|
502 } |
|
503 |
|
504 // ----------------------------------------------------------------------------- |
|
505 // CUpnpTcpSession::SetState |
|
506 // Set state to connected. |
|
507 // ----------------------------------------------------------------------------- |
|
508 // |
|
509 void CUpnpTcpSession::SetState( TUpnpTcpSessionState aState ) |
|
510 { |
|
511 LOGS1( "%i, CUpnpTcpSession::SetState()", iId ); |
|
512 iState = aState; |
|
513 switch(iState) |
|
514 { |
|
515 case EConnected: |
|
516 |
|
517 iTcpWriter->SessionConnected( ETrue ); |
|
518 break; |
|
519 case EDisconnecting: |
|
520 //outstandings writings |
|
521 iTcpWriter->SessionConnected( ETrue ); |
|
522 |
|
523 break; |
|
524 default: |
|
525 iTcpWriter->SessionConnected( EFalse ); |
|
526 if(iFTWriter) |
|
527 iFTWriter->Cancel(); |
|
528 break; |
|
529 |
|
530 } |
|
531 |
|
532 } |
|
533 |
|
534 // ----------------------------------------------------------------------------- |
|
535 // CUpnpTcpSession::IsConnected |
|
536 // Retrun connection state. |
|
537 // ----------------------------------------------------------------------------- |
|
538 // |
|
539 TBool CUpnpTcpSession::IsConnected() |
|
540 { |
|
541 return ( iState == EConnected ); |
|
542 } |
|
543 |
|
544 // ----------------------------------------------------------------------------- |
|
545 // CUpnpTcpSession::RemoteHost |
|
546 // Return remote host address. |
|
547 // ----------------------------------------------------------------------------- |
|
548 // |
|
549 TInetAddr& CUpnpTcpSession::RemoteHost() |
|
550 { |
|
551 return iAddr; |
|
552 } |
|
553 |
|
554 // ----------------------------------------------------------------------------- |
|
555 // CUpnpTcpSession::HandleErrorL |
|
556 // |
|
557 // ----------------------------------------------------------------------------- |
|
558 // |
|
559 void CUpnpTcpSession::HandleErrorL( TInt aError ) |
|
560 { |
|
561 LOGS2( "%i, CUpnpTcpSession::HandleErrorL( %i )", iId , aError); |
|
562 |
|
563 if ( aError == KErrCancel ) |
|
564 { |
|
565 return; |
|
566 } |
|
567 |
|
568 |
|
569 if(!ShuttingDown()) |
|
570 { |
|
571 if( iState == EShuttingDownWriteWait ) |
|
572 { |
|
573 ShutdownStop(); |
|
574 return; |
|
575 } |
|
576 |
|
577 switch( aError ) |
|
578 { |
|
579 case KErrNoMemory: |
|
580 NotifyTimeoutL(); |
|
581 CheckConnectionCloseL(); |
|
582 iSessionNeedsErrorReply = EFalse; |
|
583 SetState( EDisconnecting ); |
|
584 NotifyDisconnectL( RemoteHost() ); |
|
585 iDisconnectNotification = EFalse; |
|
586 StartDisconnectingTimer( KErrorTimeout ); |
|
587 break; |
|
588 |
|
589 case KErrEof: |
|
590 NotifyTimeoutL(); |
|
591 CheckConnectionCloseL(); |
|
592 iSessionNeedsErrorReply = EFalse; |
|
593 SetState( EDisconnecting ); |
|
594 NotifyDisconnectL( RemoteHost() ); |
|
595 DeleteThisSessionL( this ); |
|
596 break; |
|
597 |
|
598 case KErrServerBusy: |
|
599 iDisconnectNotification = ETrue; |
|
600 iSessionNeedsErrorReply=EFalse; |
|
601 SocketServerBusyL( RemoteHost() ); |
|
602 StartDisconnect(); |
|
603 break; |
|
604 |
|
605 case KErrDisconnected: |
|
606 CheckConnectionCloseL(); |
|
607 SetState( EDisconnecting ); |
|
608 iSessionNeedsErrorReply = EFalse; |
|
609 iDisconnectNotification = EFalse; |
|
610 StartDisconnect(); |
|
611 break; |
|
612 case KErrCouldNotConnect: |
|
613 case KErrHostUnreach: |
|
614 default: |
|
615 iSessionError = aError; |
|
616 ShutdownStop(); |
|
617 break; |
|
618 } |
|
619 } |
|
620 else |
|
621 { |
|
622 iSocketShutdown->HandleError( aError ); |
|
623 } |
|
624 |
|
625 } |
|
626 |
|
627 // ----------------------------------------------------------------------------- |
|
628 // CUpnpTcpSession::WaitWriteError |
|
629 // |
|
630 // ----------------------------------------------------------------------------- |
|
631 // |
|
632 void CUpnpTcpSession::WaitRetryError(TInt aError, TBool aStartTimer) |
|
633 { |
|
634 LOGS2( "%i, CUpnpTcpSession::WaitRetryError - %i", |
|
635 iId, aError ); |
|
636 iTimeoutTimer->Cancel(); |
|
637 if (aStartTimer) |
|
638 StartTimeoutTimer( iContinuedMessageDownload ); |
|
639 } |
|
640 |
|
641 // ----------------------------------------------------------------------------- |
|
642 // CUpnpTcpSession::StartClosingSession |
|
643 // |
|
644 // ----------------------------------------------------------------------------- |
|
645 // |
|
646 void CUpnpTcpSession::StartClosingSession() |
|
647 { |
|
648 iSessionNeedsErrorReply=EFalse; |
|
649 StartDisconnect( ETrue ); |
|
650 } |
|
651 |
|
652 // ----------------------------------------------------------------------------- |
|
653 // CUpnpTcpSession::IsPersistentConnection |
|
654 // |
|
655 // ----------------------------------------------------------------------------- |
|
656 // |
|
657 TBool CUpnpTcpSession::IsPersistentConnection() |
|
658 { |
|
659 return iIsPersistent; |
|
660 } |
|
661 |
|
662 // ----------------------------------------------------------------------------- |
|
663 // CUpnpTcpSession::IsPersistentConnection |
|
664 // |
|
665 // ----------------------------------------------------------------------------- |
|
666 // |
|
667 CUpnpHttpFileTransferReader* CUpnpTcpSession::FileTransferReader() |
|
668 { |
|
669 return iFTReader; |
|
670 } |
|
671 |
|
672 // ----------------------------------------------------------------------------- |
|
673 // CUpnpTcpSession::FileTransferWriter |
|
674 // |
|
675 // ----------------------------------------------------------------------------- |
|
676 // |
|
677 CUpnpHttpFileTransferWriter* CUpnpTcpSession::FileTransferWriter() |
|
678 { |
|
679 return iFTWriter; |
|
680 } |
|
681 |
|
682 // ----------------------------------------------------------------------------- |
|
683 // CUpnpTcpSession::IsPersistentConnection |
|
684 // |
|
685 // ----------------------------------------------------------------------------- |
|
686 // |
|
687 TBool CUpnpTcpSession::OutstandingWritings() |
|
688 { |
|
689 //whether content being served or outstanding messages to be written to the socket |
|
690 return (FileServeExists() || iTcpWriter->HasWriteRequestsToSend()); |
|
691 } |
|
692 |
|
693 // ----------------------------------------------------------------------------- |
|
694 // CUpnpTcpSession::DownloadOngoing |
|
695 // |
|
696 // ----------------------------------------------------------------------------- |
|
697 // |
|
698 TBool CUpnpTcpSession::DownloadOngoing() |
|
699 { |
|
700 //whether content being served or outstanding messages to be written to the socket |
|
701 return (FileTransferWriter() && FileTransferWriter()->IsActivated() && |
|
702 !FileTransferWriter()->IsCancelled()); |
|
703 } |
|
704 |
|
705 // ----------------------------------------------------------------------------- |
|
706 // CUpnpTcpSession::TimerCancel |
|
707 // |
|
708 // ----------------------------------------------------------------------------- |
|
709 // |
|
710 void CUpnpTcpSession::TimerCancel() |
|
711 { |
|
712 iTimeoutTimer->Cancel(); |
|
713 } |
|
714 |
|
715 // ----------------------------------------------------------------------------- |
|
716 // CUpnpTcpSession::ShuttingDown |
|
717 // |
|
718 // ----------------------------------------------------------------------------- |
|
719 // |
|
720 TBool CUpnpTcpSession::ShuttingDown() |
|
721 { |
|
722 return (iState == ENotConnected || iState == EShuttingDown ); |
|
723 } |
|
724 |
|
725 // ----------------------------------------------------------------------------- |
|
726 // CUpnpTcpSession::CloseSocketL |
|
727 // |
|
728 // ----------------------------------------------------------------------------- |
|
729 // |
|
730 void CUpnpTcpSession::CloseSocketL() |
|
731 { |
|
732 if( iDisconnectNotification ) |
|
733 { |
|
734 NotifyDisconnectL( RemoteHost() ); |
|
735 } |
|
736 else |
|
737 { |
|
738 NotifyTimeoutL(); |
|
739 } |
|
740 iState = ENotConnected; |
|
741 iSocket.Close(); |
|
742 DestroyIt( this ); |
|
743 } |
|
744 |
|
745 // ----------------------------------------------------------------------------- |
|
746 // CUpnpTcpSession::TimeoutCurrentValue |
|
747 // |
|
748 // ----------------------------------------------------------------------------- |
|
749 // |
|
750 TInt CUpnpTcpSession::TimeoutCurrentValue() |
|
751 { |
|
752 return iTimeoutCurrentValue; |
|
753 } |
|
754 |
|
755 // ----------------------------------------------------------------------------- |
|
756 // CUpnpTcpSession::CancelTcpReader() |
|
757 // |
|
758 // ----------------------------------------------------------------------------- |
|
759 // |
|
760 void CUpnpTcpSession::CancelTcpReader() |
|
761 { |
|
762 iTcpReader->Cancel(); |
|
763 } |
|
764 |
|
765 // End of File |