1 /* |
|
2 * Copyright (c) 2009 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: Writes to socket. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __SOCKETSWRITER_H__ |
|
20 #define __SOCKETSWRITER_H__ |
|
21 |
|
22 // INCLUDES |
|
23 #include <in_sock.h> |
|
24 #include "timeoutnotifier.h" |
|
25 |
|
26 // FORWARD DECLARATIONS |
|
27 class CTimeOutTimer; |
|
28 class MSocketObserver; |
|
29 |
|
30 const TInt KSocketWriteBufferSize = 1024; |
|
31 const TInt KTransferBufferSize = 8 * 1024; |
|
32 |
|
33 // CLASS DECLARATION |
|
34 class CSocketsWriter : public CActive, public MTimeOutNotifier |
|
35 { |
|
36 public: |
|
37 |
|
38 static CSocketsWriter* NewL( MSocketObserver& aEngineNotifier, |
|
39 RSocket& aSocket ); |
|
40 virtual ~CSocketsWriter(); |
|
41 |
|
42 /** |
|
43 * Add data to iTransferBuffer and start sending if not already sending |
|
44 * Leaves with KErrOverflow, if there is not enough free space. |
|
45 * This can be called as long as there is space in buffer. |
|
46 */ |
|
47 void SendL(const TDesC8& aData); |
|
48 |
|
49 void CancelSending(); |
|
50 |
|
51 /** |
|
52 * Return number of bytes that can be added to iTransferBuffer. |
|
53 */ |
|
54 TInt FreeSpaceInSendBuffer(); |
|
55 |
|
56 TInt SendBufferMaxSize(); |
|
57 |
|
58 protected: // from CActive |
|
59 |
|
60 void DoCancel(); |
|
61 void RunL(); |
|
62 |
|
63 protected: // from MTimeOutNotifier |
|
64 |
|
65 void TimerExpired(); |
|
66 |
|
67 private: // Constructors and destructors |
|
68 |
|
69 CSocketsWriter( MSocketObserver& aEngineNotifier, RSocket& aSocket ); |
|
70 void ConstructL(); |
|
71 |
|
72 private: // New functions |
|
73 |
|
74 void SendNextPacket(); |
|
75 |
|
76 private: // Enumerations |
|
77 |
|
78 enum TWriteState |
|
79 { |
|
80 ESending, |
|
81 EIdle // nothing to be sent |
|
82 }; |
|
83 |
|
84 private: // Data |
|
85 |
|
86 RSocket& iSocket; |
|
87 MSocketObserver& iObserver; |
|
88 TBuf8<KTransferBufferSize> iTransferBuffer; |
|
89 TBuf8<KSocketWriteBufferSize> iWriteBuffer; |
|
90 CTimeOutTimer* iTimer; |
|
91 TInt iTimeOut; // microseconds |
|
92 TWriteState iWriteStatus; |
|
93 }; |
|
94 |
|
95 #endif // __SOCKETSWRITER_H__ |
|
96 |
|
97 // End of File |
|