author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 17 Sep 2010 08:38:54 +0300 | |
changeset 63 | a117ad66e027 |
parent 31 | ce057bb09d0b |
permissions | -rw-r--r-- |
31 | 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: |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
#include "fdesc.h" |
|
20 |
||
21 |
TInt CSockDescBase::Socket(RSocketServ& /*aSs*/, int /*family*/, int /*style*/, int /*protocol*/) |
|
22 |
{ |
|
23 |
return KErrNotSupported; |
|
24 |
} |
|
25 |
TInt CSockDescBase::Fcntl(TUint anArg, TUint aCmd) |
|
26 |
{ |
|
27 |
//fcntl supports only F_SETFL and F_GETFL for Non-Blocking I/O |
|
28 |
//If aCmd and anArg does not match these, return with Error |
|
29 |
TInt retVal = KErrNone; |
|
30 |
||
31 |
switch( aCmd ) |
|
32 |
{ |
|
33 |
case F_SETFL: |
|
34 |
{ |
|
35 |
||
36 |
//Send the equivalent Flags of Symbian to RSocket |
|
37 |
TUint flags = iFcntlFlag; |
|
38 |
if( anArg & O_NONBLOCK ) |
|
39 |
{ |
|
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
40 |
ATOMICSOCKETOP(retVal = iSocket.SetOpt(KSONonBlockingIO, KSOLSocket),retVal = EBADF;) |
31 | 41 |
flags |= O_NONBLOCK; |
42 |
} |
|
43 |
else |
|
44 |
{ |
|
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
45 |
ATOMICSOCKETOP(retVal = iSocket.SetOpt(KSOBlockingIO, KSOLSocket),retVal = EBADF;) |
31 | 46 |
flags &= ~O_NONBLOCK; |
47 |
} |
|
48 |
if (retVal == KErrNone) |
|
49 |
{ |
|
50 |
retVal = iFcntlFlag = flags; |
|
51 |
} |
|
52 |
break; |
|
53 |
} |
|
54 |
case F_GETFL: |
|
55 |
{ |
|
56 |
// Socket descriptors are always read/write |
|
57 |
iFcntlFlag |= O_RDWR; |
|
58 |
//Return fcntl flag |
|
59 |
retVal = iFcntlFlag; |
|
60 |
break; |
|
61 |
} |
|
62 |
default: |
|
63 |
retVal = KErrNotSupported; |
|
64 |
} |
|
65 |
return retVal; |
|
66 |
||
67 |
||
68 |
} |
|
69 |
||
70 |
TInt CSockDescBase::FStat(struct stat *st) |
|
71 |
{ |
|
72 |
||
73 |
// I am a socket about which little is known |
|
74 |
st->st_mode = S_IFSOCK; |
|
75 |
st->st_blksize=0; |
|
76 |
return KErrNone; |
|
77 |
||
78 |
} |
|
79 |
||
80 |
TInt CSockDescBase::FinalClose() |
|
81 |
{ |
|
82 |
iSocket.Close(); |
|
83 |
iReadLock.Close(); |
|
84 |
iWriteLock.Close(); |
|
85 |
iIoctlLock.Close(); |
|
86 |
return KErrNone; |
|
87 |
} |
|
88 |
||
89 |
void CSockDescBase::Read(TDes8& aBuf, TRequestStatus& aStatus) |
|
90 |
{ |
|
91 |
TSockXfrLength len; |
|
92 |
TRequestStatus tempStatus; |
|
93 |
||
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
94 |
ATOMICSOCKETOP(iSocket.RecvOneOrMore(aBuf, 0, tempStatus, len),Complete(tempStatus,KErrBadHandle)) |
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
95 |
// needs a completion which returns the length |
31 | 96 |
User::WaitForRequest(tempStatus); |
97 |
if (tempStatus.Int() != KErrNone) |
|
98 |
{ |
|
99 |
Complete(aStatus, tempStatus.Int()); |
|
100 |
} |
|
101 |
else |
|
102 |
{ |
|
103 |
Complete(aStatus, len()); |
|
104 |
} |
|
105 |
} |
|
106 |
||
107 |
void CSockDescBase::Write(TDes8& aBuf, TRequestStatus& aStatus) |
|
108 |
{ |
|
109 |
TRequestStatus tempStatus; |
|
110 |
TInt bytesWritten = 0; |
|
111 |
TInt bufLength = aBuf.Length(); |
|
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
112 |
TSockXfrLength len = 0; |
31 | 113 |
do |
114 |
{ |
|
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
115 |
ATOMICSOCKETOP(iSocket.Send(aBuf.Mid(bytesWritten), 0, tempStatus, len),Complete(tempStatus,KErrBadHandle)) |
31 | 116 |
User::WaitForRequest(tempStatus); |
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
117 |
if (len() == 0 || tempStatus.Int() == KErrDisconnected ) |
31 | 118 |
{ |
119 |
break; |
|
120 |
} |
|
121 |
bytesWritten += len(); |
|
122 |
} while (bytesWritten < bufLength); |
|
123 |
if (tempStatus.Int() != KErrNone) |
|
124 |
{ |
|
125 |
Complete(aStatus, tempStatus.Int()); |
|
126 |
} |
|
127 |
else if ((len() == 0) && (bytesWritten == 0)) |
|
128 |
{ |
|
129 |
Complete(aStatus, KErrWouldBlock); |
|
130 |
} |
|
131 |
else |
|
132 |
{ |
|
133 |
//to do change request complete with actual length written when defect |
|
134 |
//is fixed |
|
135 |
Complete(aStatus, bytesWritten); |
|
136 |
} |
|
137 |
||
138 |
} |
|
139 |
||
140 |
void CSockDescBase::RecvFrom(TDes8& aDesc, TSockAddr& from, int flags, TRequestStatus& aStatus) |
|
141 |
{ |
|
142 |
||
143 |
//Map the flags to the RSocket flags |
|
144 |
TUint rSockFlags = 0; |
|
145 |
if( flags & MSG_PEEK ) //Peek at incoming data |
|
146 |
rSockFlags |= KSockReadPeek; |
|
147 |
/* No equivalent flags avaialble in RSocket for |
|
148 |
MSG_OOB and MSG_WAITALL */ |
|
149 |
||
150 |
TSockXfrLength len; |
|
151 |
TRequestStatus tempStatus; |
|
152 |
||
153 |
switch (iStyle) |
|
154 |
{ |
|
155 |
case SOCK_STREAM: |
|
156 |
// recvfrom on a stream ignores the from address - get the peername |
|
157 |
if (from.Length()) |
|
158 |
SockName(1,from); |
|
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
159 |
|
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
160 |
ATOMICSOCKETOP(iSocket.RecvOneOrMore(aDesc,rSockFlags,tempStatus,len),Complete(tempStatus,KErrBadHandle)) |
31 | 161 |
break; |
162 |
||
163 |
case SOCK_SEQPACKET: |
|
164 |
// get the peername (as above) |
|
165 |
if (from.Length()) |
|
166 |
SockName(1,from); |
|
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
167 |
ATOMICSOCKETOP(iSocket.Recv(aDesc, rSockFlags, tempStatus),Complete(tempStatus,KErrBadHandle)) |
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
168 |
|
31 | 169 |
break; |
170 |
||
171 |
default: // including SOCK_RAW, SOCK_DGRAM |
|
172 |
// assume datagram, as per behavior of original stdlib code: |
|
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
173 |
ATOMICSOCKETOP(iSocket.RecvFrom(aDesc,from,rSockFlags,tempStatus,len),Complete(tempStatus,KErrBadHandle)) |
31 | 174 |
} |
175 |
||
176 |
User::WaitForRequest(tempStatus); |
|
177 |
len = aDesc.Length(); |
|
178 |
if (tempStatus.Int() != KErrNone) |
|
179 |
{ |
|
180 |
if (tempStatus.Int() == KErrEof || tempStatus.Int() == KErrDisconnected) |
|
181 |
Complete(aStatus, len()); |
|
182 |
else |
|
183 |
Complete(aStatus, tempStatus.Int()); |
|
184 |
} |
|
185 |
else |
|
186 |
{ |
|
187 |
Complete(aStatus, len()); |
|
188 |
} |
|
189 |
||
190 |
} |
|
191 |
||
192 |
void CSockDescBase::SendTo(TDes8& aDesc, TSockAddr& to, int flags, TRequestStatus& aStatus) |
|
193 |
{ |
|
194 |
||
195 |
TRequestStatus tempStatus; |
|
196 |
TSockXfrLength len; |
|
197 |
TBool sendflg = EFalse; |
|
198 |
||
199 |
if (to.Length()==0) |
|
200 |
{ |
|
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
201 |
ATOMICSOCKETOP(iSocket.Send(aDesc,flags,tempStatus,len),Complete(tempStatus,KErrBadHandle)) |
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
202 |
sendflg = ETrue; |
31 | 203 |
} |
204 |
else |
|
205 |
{ |
|
206 |
if (isStream()) |
|
207 |
Complete(aStatus,KErrNotSupported); // can't sendto a stream |
|
208 |
else |
|
209 |
{ |
|
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
210 |
ATOMICSOCKETOP(iSocket.SendTo(aDesc,to,flags,tempStatus,len),Complete(tempStatus,KErrBadHandle)) |
31 | 211 |
sendflg = ETrue; |
212 |
} |
|
213 |
} |
|
214 |
||
215 |
if(sendflg) |
|
216 |
{ |
|
217 |
User::WaitForRequest(tempStatus); |
|
218 |
if (tempStatus.Int() != KErrNone) |
|
219 |
{ |
|
220 |
if (tempStatus.Int() == KErrEof ) |
|
221 |
Complete(aStatus, len()); |
|
222 |
else |
|
223 |
Complete(aStatus, tempStatus.Int()); |
|
224 |
} |
|
225 |
else |
|
226 |
{ |
|
227 |
Complete(aStatus, len()); |
|
228 |
} |
|
229 |
} |
|
230 |
||
231 |
||
232 |
} |
|
233 |
||
234 |
TInt CSockDescBase::CompletionStatus(TInt& aLength, TInt aStatus) |
|
235 |
{ |
|
236 |
aLength = aStatus; |
|
237 |
if (aStatus >= 0) |
|
238 |
{ |
|
239 |
return 0; |
|
240 |
} |
|
241 |
return aStatus; |
|
242 |
} |
|
243 |
||
244 |
TInt CSockDescBase::Poll(TUint aEvents) |
|
245 |
{ |
|
246 |
TInt status = 0; |
|
247 |
TInt readyEvents = 0; |
|
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
248 |
TInt err = KErrNone; |
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
249 |
ATOMICSOCKETOP(err = iSocket.GetOpt(KSOSelectPoll, KSOLSocket, status),err = KErrBadHandle) |
31 | 250 |
|
251 |
if (err != KErrNone) |
|
252 |
{ |
|
253 |
// Poll should return any of the requested events. |
|
254 |
// In case of any error, the error will be set, and can be later checked by the descriptor. |
|
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
255 |
|
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
256 |
|
31 | 257 |
// For non-blocking socket, ensure to reset "iConnectInProgress" flag for a non-connected |
258 |
// socket on which a connection is pending. |
|
259 |
if(GetConnectionProgress()) |
|
260 |
{ |
|
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
261 |
iPollErr = err; |
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
262 |
|
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
263 |
SetConnectionProgress(EFalse); |
31 | 264 |
} |
265 |
||
266 |
// set all the events that has been requested for |
|
267 |
// This handles a scenario where connect fails( in loopback ) |
|
268 |
// here poll should return all the events requested as ready |
|
269 |
// not KErrNone or failure value as returning KErrNone will indicate |
|
270 |
// no events are ready and notifyactivity will be used though the event has |
|
271 |
// completed |
|
272 |
if( aEvents & EReadyForReading ) |
|
273 |
{ |
|
274 |
readyEvents |= EReadyForReading; |
|
275 |
} |
|
276 |
if( aEvents & EReadyForWriting ) |
|
277 |
{ |
|
278 |
readyEvents |= EReadyForWriting; |
|
279 |
} |
|
280 |
if( aEvents & EAnyException ) |
|
281 |
{ |
|
282 |
readyEvents |= EAnyException; |
|
283 |
} |
|
284 |
return readyEvents; |
|
285 |
} |
|
286 |
||
287 |
if ((status & KSockSelectRead) && (aEvents & EReadyForReading)) |
|
288 |
{ |
|
289 |
readyEvents |= EReadyForReading; |
|
290 |
} |
|
291 |
||
292 |
if ((status & KSockSelectWrite) && (aEvents & EReadyForWriting)) |
|
293 |
{ |
|
294 |
readyEvents |= EReadyForWriting; |
|
295 |
} |
|
296 |
||
297 |
if (status & KSockSelectExcept) |
|
298 |
{ |
|
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
299 |
|
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
300 |
if (GetConnectionProgress()) |
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
301 |
{ |
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
302 |
TInt val = -1; |
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
303 |
TInt ret = KErrNone; |
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
304 |
ATOMICSOCKETOP(ret = iSocket.GetOpt(KSOSelectLastError, KSOLSocket, val),ret = KErrBadHandle) |
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
305 |
|
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
306 |
(iPollErr = ret) || (iPollErr = val); |
31 | 307 |
TBool setExceptFd = ETrue; |
308 |
// Some special checks for non-blocking sockets. |
|
309 |
if(aEvents & EReadyForWriting) |
|
310 |
{ |
|
311 |
readyEvents |= EReadyForWriting; |
|
312 |
setExceptFd = EFalse; |
|
313 |
} |
|
314 |
||
315 |
if(aEvents & EReadyForReading) |
|
316 |
{ |
|
317 |
readyEvents |= EReadyForReading; |
|
318 |
setExceptFd = EFalse; |
|
319 |
} |
|
320 |
||
321 |
if(setExceptFd && (aEvents & EAnyException)) |
|
322 |
{ |
|
323 |
readyEvents |= EAnyException; |
|
324 |
} |
|
325 |
} |
|
326 |
else |
|
327 |
{ |
|
328 |
if(aEvents & EAnyException) |
|
329 |
{ |
|
330 |
readyEvents |= EAnyException; |
|
331 |
} |
|
332 |
} |
|
333 |
} |
|
334 |
||
335 |
if(GetConnectionProgress() && readyEvents) |
|
336 |
{ |
|
337 |
SetConnectionProgress(EFalse); |
|
338 |
} |
|
339 |
||
340 |
return readyEvents; |
|
341 |
} |
|
342 |
||
343 |
/* Register for notification of activity */ |
|
344 |
TInt CSockDescBase::NotifyActivity(TUint aEvents, TRequestStatus& aRequest, TTimeIntervalMicroSeconds32 timeout) |
|
345 |
{ |
|
346 |
if (timeout.Int()) |
|
347 |
{ |
|
348 |
TInt ret = iIoctlLock.Wait(timeout.Int()); |
|
349 |
if (ret != KErrNone) |
|
350 |
{ |
|
351 |
return KErrCompletion; |
|
352 |
} |
|
353 |
} |
|
354 |
else |
|
355 |
{ |
|
356 |
iIoctlLock.Wait(); |
|
357 |
} |
|
358 |
||
359 |
iSelectEvents() = 0; |
|
360 |
||
361 |
if (aEvents & EReadyForReading) |
|
362 |
{ |
|
363 |
iSelectEvents() = KSockSelectRead; |
|
364 |
} |
|
365 |
if (aEvents & EReadyForWriting) |
|
366 |
{ |
|
367 |
iSelectEvents() |= KSockSelectWrite; |
|
368 |
} |
|
369 |
if (aEvents & EAnyException) |
|
370 |
{ |
|
371 |
iSelectEvents() |= KSockSelectExcept; |
|
372 |
} |
|
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
373 |
ATOMICSOCKETOP(iSocket.Ioctl(KIOctlSelect, aRequest, &iSelectEvents, KSOLSocket),Complete(aRequest,KErrBadHandle)) |
31 | 374 |
return KErrNone; |
375 |
} |
|
376 |
||
377 |
// ----------------------------------------------------------------------------- |
|
378 |
// CSockDescBase::TweakWatchedEvents |
|
379 |
// Requests for socket behaviour specific additional events |
|
380 |
// ----------------------------------------------------------------------------- |
|
381 |
// |
|
382 |
void CSockDescBase::TweakWatchedEvents(TUint& events) |
|
383 |
{ |
|
384 |
if((events & EReadyForReading) || (events & EReadyForWriting)) |
|
385 |
{ |
|
386 |
// Handles scenario of select called with writefds, after a non blocking connect on a socket |
|
387 |
// as per connect specification, select with the writefds after connect should |
|
388 |
// set writefds, irrespective of if the connection is successful or failure |
|
389 |
// We request for an exception event, as in Symbian connect failure is |
|
390 |
// an exception |
|
391 |
if(GetConnectionProgress()) |
|
392 |
{ |
|
393 |
events |= EAnyException; |
|
394 |
} |
|
395 |
} |
|
396 |
} |
|
397 |
// ----------------------------------------------------------------------------- |
|
398 |
// CSockDescBase::TweakReadyEvents |
|
399 |
// Prepares the socket behaviours specific output events |
|
400 |
// ----------------------------------------------------------------------------- |
|
401 |
// |
|
402 |
TInt CSockDescBase::TweakReadyEvents(TInt errval) |
|
403 |
{ |
|
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
404 |
|
31 | 405 |
TInt returnEvents = 0; |
406 |
if( errval >= KErrNone ) |
|
407 |
{ |
|
408 |
// This file descriptor is socket-like |
|
409 |
// SelectEvents will also signal ioctlLock. |
|
410 |
// This hack allows other threads to issue an ioctl on this socket now rather than later. |
|
411 |
const TUint events = GetSelectEvents(); |
|
412 |
if (events & KSockSelectRead) |
|
413 |
{ |
|
414 |
returnEvents |= EReadyForReading; |
|
415 |
} |
|
416 |
if (events & KSockSelectWrite) |
|
417 |
{ |
|
418 |
returnEvents |= EReadyForWriting; |
|
419 |
} |
|
420 |
if (events & KSockSelectExcept) |
|
421 |
{ |
|
422 |
// if it is a case of non blocking connect check for the flag |
|
423 |
// though the flag indicates connection is in progress, we come out of |
|
424 |
// waitforNrequest only after a event |
|
425 |
if(GetConnectionProgress()) |
|
426 |
{ |
|
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
427 |
|
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
428 |
TInt val = -1; |
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
429 |
TInt ret = KErrNone; |
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
430 |
ATOMICSOCKETOP(ret = iSocket.GetOpt(KSOSelectLastError, KSOLSocket, val),ret = KErrBadHandle) |
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
431 |
(iPollErr = ret) || (iPollErr = val); |
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
432 |
|
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
433 |
|
31 | 434 |
returnEvents |= EReadyForReading; |
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
435 |
returnEvents |= EReadyForWriting; |
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
436 |
returnEvents |= EAnyException; |
31 | 437 |
} |
438 |
else |
|
439 |
{ |
|
440 |
returnEvents |= EAnyException; |
|
441 |
} |
|
442 |
} |
|
443 |
} |
|
444 |
else |
|
445 |
{ |
|
446 |
if( GetConnectionProgress() ) |
|
447 |
{ |
|
448 |
// Dummy call to retrieve select events also unlocks the socket |
|
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
449 |
const TUint events = GetSelectEvents(); |
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
450 |
|
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
451 |
TInt val = -1; |
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
452 |
TInt ret = KErrNone; |
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
453 |
ATOMICSOCKETOP(ret = iSocket.GetOpt(KSOSelectLastError, KSOLSocket, val),ret = KErrBadHandle) |
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
454 |
(iPollErr = ret) || (iPollErr = val); |
31 | 455 |
// set all the events that has been requested for |
456 |
// This handles a scenario where connect fails( in loopback ) |
|
457 |
// here all the events requested should be ready ready |
|
458 |
// Since PrepareOutputEvents is not aware of the events requested, all are |
|
459 |
// set as ready and it will be filteret in select |
|
460 |
returnEvents |= EReadyForWriting; |
|
461 |
returnEvents |= EReadyForReading; |
|
462 |
returnEvents |= EAnyException; |
|
463 |
} |
|
464 |
else |
|
465 |
{ |
|
466 |
returnEvents |= EAnyException; |
|
467 |
} |
|
468 |
} |
|
469 |
return returnEvents; |
|
470 |
} |
|
471 |
||
472 |
void CSockDescBase::CancelNotify() |
|
473 |
{ |
|
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
474 |
ATOMICSOCKETOP(iSocket.CancelIoctl(),NOP) |
31 | 475 |
iIoctlLock.Signal(); |
476 |
} |
|
477 |
||
478 |
TInt CSockDescBase::Listen(TUint qSize) |
|
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
479 |
{ |
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
480 |
TInt ret = KErrNone; |
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
481 |
ATOMICSOCKETOP(ret = iSocket.Listen(qSize), return KErrBadHandle) |
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
482 |
return ret; |
31 | 483 |
} |
484 |
||
485 |
void CSockDescBase::ReadCancel() |
|
486 |
{ |
|
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
487 |
ATOMICSOCKETOP(iSocket.CancelRecv(),NOP) |
31 | 488 |
} |
489 |
||
490 |
TInt CSockDescBase::ReadCompletion(TDes8& /*aBuf*/, TInt aStatus) |
|
491 |
{ |
|
492 |
if(KErrNone == aStatus) |
|
493 |
{ |
|
494 |
return iLength(); |
|
495 |
} |
|
496 |
return aStatus; |
|
497 |
} |
|
498 |
||
499 |
void CSockDescBase::RecvFromCancel() |
|
500 |
{ |
|
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
501 |
ATOMICSOCKETOP(iSocket.CancelRecv(),NOP) |
31 | 502 |
} |
503 |
||
504 |
void CSockDescBase::SendToCancel() |
|
505 |
{ |
|
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
506 |
ATOMICSOCKETOP(iSocket.CancelSend(),NOP) |
31 | 507 |
} |
508 |
||
509 |
void CSockDescBase::WriteCancel() |
|
510 |
{ |
|
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
511 |
ATOMICSOCKETOP(iSocket.CancelWrite(),NOP) |
31 | 512 |
} |
513 |
||
514 |
TInt CSockDescBase::SockName(int anEnd, TSockAddr& anAddr) |
|
515 |
{ |
|
516 |
const TUint KBadFamily = 0xFF000000; |
|
517 |
||
518 |
TUSockAddr *addr; |
|
519 |
||
520 |
addr = (TUSockAddr*)&anAddr; |
|
521 |
if (addr->iError != 0) |
|
522 |
{ |
|
523 |
return addr->iError; |
|
524 |
} |
|
525 |
||
526 |
anAddr.SetFamily(KBadFamily); |
|
527 |
if (anEnd==0) |
|
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
528 |
ATOMICSOCKETOP(iSocket.LocalName(anAddr),NOP) |
31 | 529 |
else |
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
530 |
ATOMICSOCKETOP(iSocket.RemoteName(anAddr),NOP) |
31 | 531 |
if (anAddr.Family()==KBadFamily) |
532 |
return ENOTCONN; // assume that the call failed, but there is no way to find out why |
|
533 |
return KErrNone; |
|
534 |
} |
|
535 |
||
536 |
void CSockDescBase::Shutdown(TUint aHow,TRequestStatus& aStatus) |
|
537 |
{ |
|
538 |
RSocket::TShutdown how; |
|
539 |
||
540 |
switch (aHow) |
|
541 |
{ |
|
542 |
case SHUT_RD: |
|
543 |
how = RSocket::EStopInput; |
|
544 |
break; |
|
545 |
case SHUT_WR: |
|
546 |
how = RSocket::EStopOutput; |
|
547 |
break; |
|
548 |
case SHUT_RDWR: |
|
549 |
how = RSocket::EImmediate; |
|
550 |
break; |
|
551 |
default: |
|
552 |
Complete(aStatus,KErrArgument); // Invalid argument |
|
553 |
return; |
|
554 |
} |
|
63
a117ad66e027
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
555 |
ATOMICSOCKETOP(iSocket.Shutdown(how,aStatus),Complete(aStatus,KErrBadHandle)) |
31 | 556 |
return; |
557 |
} |