|
1 // Copyright (c) 2005-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 // Name : CSocketOpt.cpp |
|
15 // Part of : ConnectionMgr |
|
16 // See class definition below. |
|
17 // Version : SIP/4.0 |
|
18 // |
|
19 |
|
20 |
|
21 |
|
22 #include "CSocketOpt.h" |
|
23 #include "SipLogs.h" |
|
24 |
|
25 // ----------------------------------------------------------------------------- |
|
26 // CSocketOpt::NewLC |
|
27 // ----------------------------------------------------------------------------- |
|
28 // |
|
29 CSocketOpt* CSocketOpt::NewLC( |
|
30 TUint aOptionName, |
|
31 TUint aOptionLevel, |
|
32 TInt aOption ) |
|
33 { |
|
34 CSocketOpt* self = |
|
35 new ( ELeave ) CSocketOpt( aOptionName, aOptionLevel, aOption ); |
|
36 CleanupStack::PushL( self ); |
|
37 self->ConstructL(); |
|
38 return self; |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CSocketOpt::NewLC |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 CSocketOpt* CSocketOpt::NewLC( |
|
46 TUint aOptionName, |
|
47 TUint aOptionLevel, |
|
48 const TDesC8& aOption ) |
|
49 { |
|
50 CSocketOpt* self = |
|
51 new ( ELeave ) CSocketOpt( aOptionName, aOptionLevel ); |
|
52 CleanupStack::PushL( self ); |
|
53 self->ConstructL( aOption ); |
|
54 return self; |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CSocketOpt::~CSocketOpt |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 CSocketOpt::~CSocketOpt() |
|
62 { |
|
63 delete iOptionBuf; |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CSocketOpt::ConstructL |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 void CSocketOpt::ConstructL( const TDesC8& aOption ) |
|
71 { |
|
72 if ( aOption != KNullDesC8 ) |
|
73 { |
|
74 iOptionBuf = aOption.AllocL(); |
|
75 } |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CSocketOpt::CSocketOpt |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 CSocketOpt::CSocketOpt( |
|
83 TUint aOptionName, |
|
84 TUint aOptionLevel, |
|
85 TInt aOption ) : |
|
86 iOptionName( aOptionName ), |
|
87 iOptionLevel( aOptionLevel ), |
|
88 iOption( aOption ) |
|
89 { |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // CSocketOpt::SetOpt |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 TUint CSocketOpt::OptionName() const |
|
97 { |
|
98 return iOptionName; |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CSocketOpt::SetOptL |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 CSocketOpt* CSocketOpt::SetOptL( RSocket& aSocket ) |
|
106 { |
|
107 __SIP_LOG( "CSocketOpt::SetOptL" ) |
|
108 |
|
109 CSocketOpt* previousOpt( NULL ); |
|
110 TInt err( KErrNone ); |
|
111 |
|
112 if ( iOptionBuf ) |
|
113 { |
|
114 // Errors are ignored |
|
115 HBufC8* optionBuf = HBufC8::NewLC( iOptionBuf->Des().MaxLength() * 2 ); |
|
116 TPtr8 optionBufPtr = optionBuf->Des(); |
|
117 err = aSocket.GetOpt( iOptionName, iOptionLevel, optionBufPtr ); |
|
118 if ( !err ) |
|
119 { |
|
120 previousOpt = CSocketOpt::NewLC( iOptionName, iOptionLevel, *optionBuf ); |
|
121 CleanupStack::Pop( previousOpt ); |
|
122 } |
|
123 __SIP_INT_LOG1( "CSocketOpt::SetOptL, previous opt read, err:", err ) |
|
124 CleanupStack::PopAndDestroy( optionBuf ); |
|
125 err = aSocket.SetOpt( iOptionName, iOptionLevel, *iOptionBuf ); |
|
126 } |
|
127 else |
|
128 { |
|
129 // Errors are ignored |
|
130 TInt optionVal( 0 ); |
|
131 err = aSocket.GetOpt( iOptionName, iOptionLevel, optionVal ); |
|
132 if ( !err ) |
|
133 { |
|
134 previousOpt = CSocketOpt::NewLC( iOptionName, iOptionLevel, optionVal ); |
|
135 CleanupStack::Pop( previousOpt ); |
|
136 } |
|
137 __SIP_INT_LOG1( "CSocketOpt::SetOptL, previous opt read, err:", err ) |
|
138 err = aSocket.SetOpt( iOptionName, iOptionLevel, iOption ); |
|
139 } |
|
140 |
|
141 __SIP_INT_LOG1( "CSocketOpt::SetOptL, exit, err:", err ) |
|
142 |
|
143 return previousOpt; |
|
144 } |
|
145 |
|
146 // end of file |