sl@0
|
1 |
// Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include "SYSIF.H"
|
sl@0
|
17 |
#include "FDESC.H"
|
sl@0
|
18 |
#include "LTIME.H"
|
sl@0
|
19 |
#include "LPOSIX.H"
|
sl@0
|
20 |
#include <fcntl.h>
|
sl@0
|
21 |
#include <sys/errno.h>
|
sl@0
|
22 |
#include <sys/serial.h>
|
sl@0
|
23 |
|
sl@0
|
24 |
// System Interface for thread-local form of STDLIB
|
sl@0
|
25 |
|
sl@0
|
26 |
/**
|
sl@0
|
27 |
Two-phase constructor method to create a CLocalSystemInterface instance.
|
sl@0
|
28 |
*/
|
sl@0
|
29 |
CLocalSystemInterface* CLocalSystemInterface::NewL()
|
sl@0
|
30 |
{
|
sl@0
|
31 |
CLocalSystemInterface* self = new (ELeave) CLocalSystemInterface();
|
sl@0
|
32 |
CleanupStack::PushL(self);
|
sl@0
|
33 |
self->ConstructL();
|
sl@0
|
34 |
CleanupStack::Pop(self);
|
sl@0
|
35 |
return self;
|
sl@0
|
36 |
}
|
sl@0
|
37 |
|
sl@0
|
38 |
/**
|
sl@0
|
39 |
Constructor.
|
sl@0
|
40 |
*/
|
sl@0
|
41 |
CLocalSystemInterface::CLocalSystemInterface()
|
sl@0
|
42 |
{
|
sl@0
|
43 |
}
|
sl@0
|
44 |
|
sl@0
|
45 |
/**
|
sl@0
|
46 |
Second-phase constructor.
|
sl@0
|
47 |
Initialises some data members.
|
sl@0
|
48 |
This function leaves if any system-wide error happens.
|
sl@0
|
49 |
*/
|
sl@0
|
50 |
void CLocalSystemInterface::ConstructL()
|
sl@0
|
51 |
{
|
sl@0
|
52 |
iFids.InitL();
|
sl@0
|
53 |
|
sl@0
|
54 |
CTtyDesc* console=new CTtyDesc;
|
sl@0
|
55 |
User::LeaveIfNull(console);
|
sl@0
|
56 |
|
sl@0
|
57 |
iFids.Default(console);
|
sl@0
|
58 |
console->Close();
|
sl@0
|
59 |
|
sl@0
|
60 |
User::LeaveIfError(iFs.Connect());
|
sl@0
|
61 |
User::LeaveIfError(PosixFilesystem::SetDefaultDir(iFs));
|
sl@0
|
62 |
}
|
sl@0
|
63 |
|
sl@0
|
64 |
CLocalSystemInterface::~CLocalSystemInterface()
|
sl@0
|
65 |
//
|
sl@0
|
66 |
// Shut down all server connections in use
|
sl@0
|
67 |
//
|
sl@0
|
68 |
{
|
sl@0
|
69 |
iFids.Close();
|
sl@0
|
70 |
iCs.Close();
|
sl@0
|
71 |
iSs.Close();
|
sl@0
|
72 |
iFs.Close();
|
sl@0
|
73 |
}
|
sl@0
|
74 |
|
sl@0
|
75 |
MSystemInterface& CLocalSystemInterface::Clone()
|
sl@0
|
76 |
{
|
sl@0
|
77 |
iUseCount++;
|
sl@0
|
78 |
return *this;
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
void CLocalSystemInterface::Release()
|
sl@0
|
82 |
{
|
sl@0
|
83 |
if (--iUseCount<0)
|
sl@0
|
84 |
delete this;
|
sl@0
|
85 |
}
|
sl@0
|
86 |
|
sl@0
|
87 |
void CLocalSystemInterface::TerminateProcess(int status)
|
sl@0
|
88 |
{
|
sl@0
|
89 |
delete this;
|
sl@0
|
90 |
RProcess().Terminate(status);
|
sl@0
|
91 |
}
|
sl@0
|
92 |
|
sl@0
|
93 |
|
sl@0
|
94 |
// Simple layer over PosixFilesystem
|
sl@0
|
95 |
|
sl@0
|
96 |
wchar_t * CLocalSystemInterface::getcwd (wchar_t* buf, unsigned long len, int& anErrno)
|
sl@0
|
97 |
{
|
sl@0
|
98 |
return PosixFilesystem::getcwd(iFs,buf,len,anErrno);
|
sl@0
|
99 |
}
|
sl@0
|
100 |
|
sl@0
|
101 |
int CLocalSystemInterface::chdir (const wchar_t* aPath, int& anErrno)
|
sl@0
|
102 |
{
|
sl@0
|
103 |
return PosixFilesystem::chdir(iFs,aPath,anErrno);
|
sl@0
|
104 |
}
|
sl@0
|
105 |
|
sl@0
|
106 |
int CLocalSystemInterface::rmdir (const wchar_t* aPath, int& anErrno)
|
sl@0
|
107 |
{
|
sl@0
|
108 |
return PosixFilesystem::rmdir(iFs,aPath,anErrno);
|
sl@0
|
109 |
}
|
sl@0
|
110 |
|
sl@0
|
111 |
int CLocalSystemInterface::mkdir (const wchar_t* aPath, int perms, int& anErrno)
|
sl@0
|
112 |
{
|
sl@0
|
113 |
return PosixFilesystem::mkdir(iFs,aPath,perms,anErrno);
|
sl@0
|
114 |
}
|
sl@0
|
115 |
|
sl@0
|
116 |
int CLocalSystemInterface::stat (const wchar_t* name, struct stat *st, int& anErrno)
|
sl@0
|
117 |
{
|
sl@0
|
118 |
return PosixFilesystem::stat(iFs,name,st,anErrno);
|
sl@0
|
119 |
}
|
sl@0
|
120 |
|
sl@0
|
121 |
int CLocalSystemInterface::chmod (const wchar_t* name, int perms, int& anErrno)
|
sl@0
|
122 |
{
|
sl@0
|
123 |
return PosixFilesystem::chmod(iFs,name,perms,anErrno);
|
sl@0
|
124 |
}
|
sl@0
|
125 |
|
sl@0
|
126 |
int CLocalSystemInterface::unlink (const wchar_t* name, int& anErrno)
|
sl@0
|
127 |
{
|
sl@0
|
128 |
return PosixFilesystem::unlink(iFs,name,anErrno);
|
sl@0
|
129 |
}
|
sl@0
|
130 |
|
sl@0
|
131 |
int CLocalSystemInterface::rename (const wchar_t* oldname, const wchar_t* newname, int& anErrno)
|
sl@0
|
132 |
{
|
sl@0
|
133 |
return PosixFilesystem::rename(iFs,oldname,newname,anErrno);
|
sl@0
|
134 |
}
|
sl@0
|
135 |
|
sl@0
|
136 |
|
sl@0
|
137 |
TInt CLocalSystemInterface::ResolvePath (TParse& aResult, const wchar_t* path, TDes* aFilename)
|
sl@0
|
138 |
{
|
sl@0
|
139 |
return PosixFilesystem::ResolvePath(iFs, aResult, path, aFilename);
|
sl@0
|
140 |
}
|
sl@0
|
141 |
|
sl@0
|
142 |
// Simple layer over CFileTable synchronous routines
|
sl@0
|
143 |
|
sl@0
|
144 |
int CLocalSystemInterface::open (const wchar_t* name, int mode, int perms, int& anErrno)
|
sl@0
|
145 |
{
|
sl@0
|
146 |
//at this point we need to know if it is a serial port or file
|
sl@0
|
147 |
if ((L'C' == name[0]) && (L'O' == name[1]) && (L'M' == name[2]) && (L':' == name[4]) && ((name[3] >= L'1') && (name[3] <= L'9')) ||
|
sl@0
|
148 |
(L'I' == name[0]) && (L'R' == name[1]) && (L'C' == name[2]) && (L'O' == name[3]) && (L'M' == name[4]) && (L':' == name[6]) && ((name[5] >= L'1') && (name[5] <= L'9')))
|
sl@0
|
149 |
return iFids.open(name,mode,perms,anErrno, iCs);
|
sl@0
|
150 |
else
|
sl@0
|
151 |
return iFids.open(name,mode,perms,anErrno, iFs);
|
sl@0
|
152 |
}
|
sl@0
|
153 |
|
sl@0
|
154 |
int CLocalSystemInterface::dup (int fid, int& anErrno)
|
sl@0
|
155 |
{
|
sl@0
|
156 |
return iFids.dup(fid,anErrno);
|
sl@0
|
157 |
}
|
sl@0
|
158 |
|
sl@0
|
159 |
int CLocalSystemInterface::dup2 (int fid, int fid2, int& anErrno)
|
sl@0
|
160 |
{
|
sl@0
|
161 |
return iFids.dup2(fid,fid2,anErrno);
|
sl@0
|
162 |
}
|
sl@0
|
163 |
|
sl@0
|
164 |
int CLocalSystemInterface::close (int fid, int& anErrno)
|
sl@0
|
165 |
{
|
sl@0
|
166 |
// return iFids.close(fid,anErrno);
|
sl@0
|
167 |
return iFids.userclose(fid,anErrno);
|
sl@0
|
168 |
}
|
sl@0
|
169 |
|
sl@0
|
170 |
int CLocalSystemInterface::lseek (int fid, int offset, int whence, int& anErrno)
|
sl@0
|
171 |
{
|
sl@0
|
172 |
return iFids.lseek(fid,offset,whence,anErrno);
|
sl@0
|
173 |
}
|
sl@0
|
174 |
|
sl@0
|
175 |
int CLocalSystemInterface::fstat (int fid, struct stat *st, int& anErrno)
|
sl@0
|
176 |
{
|
sl@0
|
177 |
return iFids.fstat(fid,st,anErrno);
|
sl@0
|
178 |
}
|
sl@0
|
179 |
|
sl@0
|
180 |
int CLocalSystemInterface::socket (int family, int style, int protocol, int& anErrno)
|
sl@0
|
181 |
{
|
sl@0
|
182 |
return iFids.socket(family,style,protocol,anErrno,iSs);
|
sl@0
|
183 |
}
|
sl@0
|
184 |
|
sl@0
|
185 |
int CLocalSystemInterface::listen (int fid, int n, int& anErrno)
|
sl@0
|
186 |
{
|
sl@0
|
187 |
return iFids.listen(fid,n,anErrno);
|
sl@0
|
188 |
}
|
sl@0
|
189 |
|
sl@0
|
190 |
int CLocalSystemInterface::bind (int fid, struct sockaddr* addr, unsigned long size, int& anErrno)
|
sl@0
|
191 |
{
|
sl@0
|
192 |
TUSockAddr address(addr,size);
|
sl@0
|
193 |
return iFids.bind(fid,address,anErrno);
|
sl@0
|
194 |
}
|
sl@0
|
195 |
|
sl@0
|
196 |
int CLocalSystemInterface::sockname (int fid, struct sockaddr* addr, unsigned long* size, int anEnd, int& anErrno)
|
sl@0
|
197 |
{
|
sl@0
|
198 |
TUSockAddr address(addr);
|
sl@0
|
199 |
TInt ret=iFids.sockname(fid,address,anEnd,anErrno);
|
sl@0
|
200 |
if (ret==0)
|
sl@0
|
201 |
address.Get(addr,size);
|
sl@0
|
202 |
return ret;
|
sl@0
|
203 |
}
|
sl@0
|
204 |
|
sl@0
|
205 |
int CLocalSystemInterface::getsockopt (int fid, int level, int opt, void* buf, unsigned long* len, int& anErrno)
|
sl@0
|
206 |
{
|
sl@0
|
207 |
return iFids.getsockopt(fid,level,opt,buf,len,anErrno);
|
sl@0
|
208 |
}
|
sl@0
|
209 |
|
sl@0
|
210 |
int CLocalSystemInterface::setsockopt (int fid, int level, int opt, void* buf, unsigned long len, int& anErrno)
|
sl@0
|
211 |
{
|
sl@0
|
212 |
return iFids.setsockopt(fid,level,opt,buf,len,anErrno);
|
sl@0
|
213 |
}
|
sl@0
|
214 |
|
sl@0
|
215 |
wchar_t* CLocalSystemInterface::getenv (const wchar_t* name)
|
sl@0
|
216 |
{
|
sl@0
|
217 |
return iEnv.getenv(name);
|
sl@0
|
218 |
}
|
sl@0
|
219 |
|
sl@0
|
220 |
void CLocalSystemInterface::unsetenv (const wchar_t* name)
|
sl@0
|
221 |
{
|
sl@0
|
222 |
iEnv.unsetenv(name);
|
sl@0
|
223 |
}
|
sl@0
|
224 |
|
sl@0
|
225 |
int CLocalSystemInterface::setenv (const wchar_t* name, const wchar_t* value, int rewrite, int& anErrno)
|
sl@0
|
226 |
{
|
sl@0
|
227 |
return iEnv.setenv(name,value,rewrite,anErrno);
|
sl@0
|
228 |
}
|
sl@0
|
229 |
|
sl@0
|
230 |
|
sl@0
|
231 |
int CLocalSystemInterface::popen3 (const wchar_t *, const wchar_t *, const wchar_t *, wchar_t**, int [3], int& anErrno)
|
sl@0
|
232 |
{
|
sl@0
|
233 |
return MapError(KErrNotSupported,anErrno);
|
sl@0
|
234 |
}
|
sl@0
|
235 |
|
sl@0
|
236 |
int CLocalSystemInterface::waitpid (int, int*, int, int& anErrno)
|
sl@0
|
237 |
{
|
sl@0
|
238 |
return MapError(KErrNotSupported,anErrno);
|
sl@0
|
239 |
}
|
sl@0
|
240 |
|
sl@0
|
241 |
// Synchronous layer over CFileTable asynchronous routines
|
sl@0
|
242 |
|
sl@0
|
243 |
int CLocalSystemInterface::read (int fid, char* buf, unsigned long len, int& anErrno)
|
sl@0
|
244 |
{
|
sl@0
|
245 |
CFileDescBase* f=0;
|
sl@0
|
246 |
TBool patchErr = EFalse;
|
sl@0
|
247 |
|
sl@0
|
248 |
TInt err=iFids.Asynch(fid,f);
|
sl@0
|
249 |
if (!err)
|
sl@0
|
250 |
{
|
sl@0
|
251 |
TRequestStatus readStatus;
|
sl@0
|
252 |
TRequestStatus timerStatus(KRequestPending);
|
sl@0
|
253 |
RTimer theTimer;
|
sl@0
|
254 |
TBool timerRunning = EFalse;
|
sl@0
|
255 |
|
sl@0
|
256 |
TPtr8 ptr((TText8 *)buf, len);
|
sl@0
|
257 |
|
sl@0
|
258 |
if (f->TimedRead())
|
sl@0
|
259 |
{
|
sl@0
|
260 |
TTimeIntervalMicroSeconds32 timeout(f->TimeoutValue()*1000);
|
sl@0
|
261 |
theTimer.CreateLocal();
|
sl@0
|
262 |
theTimer.After(timerStatus, timeout);
|
sl@0
|
263 |
timerRunning = ETrue;
|
sl@0
|
264 |
}
|
sl@0
|
265 |
|
sl@0
|
266 |
f->Read(ptr, readStatus);
|
sl@0
|
267 |
|
sl@0
|
268 |
User::WaitForRequest(readStatus, timerStatus);
|
sl@0
|
269 |
|
sl@0
|
270 |
if (timerRunning)
|
sl@0
|
271 |
{
|
sl@0
|
272 |
if (timerStatus.Int() != KRequestPending)
|
sl@0
|
273 |
{
|
sl@0
|
274 |
//cancel the read and wait for it
|
sl@0
|
275 |
f->ReadCancel();
|
sl@0
|
276 |
patchErr = ETrue; //report this as a timeout not a cancel!!
|
sl@0
|
277 |
User::WaitForRequest(readStatus);
|
sl@0
|
278 |
}
|
sl@0
|
279 |
else
|
sl@0
|
280 |
{
|
sl@0
|
281 |
//if the timer was in operation
|
sl@0
|
282 |
//cancel the timer
|
sl@0
|
283 |
theTimer.Cancel();
|
sl@0
|
284 |
User::WaitForRequest(timerStatus);
|
sl@0
|
285 |
}
|
sl@0
|
286 |
theTimer.Close();
|
sl@0
|
287 |
}
|
sl@0
|
288 |
|
sl@0
|
289 |
err=f->ReadCompletion(ptr, readStatus.Int());
|
sl@0
|
290 |
f->Close(); // balances the Dup() in CFileTable::Asynch()
|
sl@0
|
291 |
if (err==0)
|
sl@0
|
292 |
return ptr.Length();
|
sl@0
|
293 |
}
|
sl@0
|
294 |
if (patchErr)
|
sl@0
|
295 |
err = ETIMEDOUT;
|
sl@0
|
296 |
|
sl@0
|
297 |
return MapError(err,anErrno);
|
sl@0
|
298 |
}
|
sl@0
|
299 |
|
sl@0
|
300 |
int CLocalSystemInterface::write (int fid, const char* buf, unsigned long len, int& anErrno)
|
sl@0
|
301 |
{
|
sl@0
|
302 |
CFileDescBase* f=0;
|
sl@0
|
303 |
TInt err=iFids.Asynch(fid,f);
|
sl@0
|
304 |
if (!err)
|
sl@0
|
305 |
{
|
sl@0
|
306 |
TRequestStatus status;
|
sl@0
|
307 |
TPtr8 ptr((TText8 *)buf, len, len);
|
sl@0
|
308 |
f->Write(ptr,status);
|
sl@0
|
309 |
User::WaitForRequest(status);
|
sl@0
|
310 |
err=f->WriteCompletion(ptr, status.Int());
|
sl@0
|
311 |
f->Close(); // balances the Dup() in CFileTable::Asynch()
|
sl@0
|
312 |
if (err==0)
|
sl@0
|
313 |
return ptr.Length();
|
sl@0
|
314 |
}
|
sl@0
|
315 |
return MapError(err,anErrno);
|
sl@0
|
316 |
}
|
sl@0
|
317 |
|
sl@0
|
318 |
int CLocalSystemInterface::recvfrom (int fid, char* buf, unsigned long len, int flags, struct sockaddr* from, unsigned long* fromsize, int& anErrno)
|
sl@0
|
319 |
{
|
sl@0
|
320 |
CFileDescBase* f=0;
|
sl@0
|
321 |
TInt err=iFids.Asynch(fid,f);
|
sl@0
|
322 |
if (!err)
|
sl@0
|
323 |
{
|
sl@0
|
324 |
TRequestStatus status;
|
sl@0
|
325 |
TPtr8 ptr((TText8 *)buf, len);
|
sl@0
|
326 |
TUSockAddr addr(from);
|
sl@0
|
327 |
f->RecvFrom(ptr,addr,flags,status);
|
sl@0
|
328 |
User::WaitForRequest(status);
|
sl@0
|
329 |
TInt ret=0;
|
sl@0
|
330 |
err=f->RecvFromCompletion(ret, status.Int());
|
sl@0
|
331 |
f->Close(); // balances the Dup() in CFileTable::Asynch()
|
sl@0
|
332 |
if (err==0)
|
sl@0
|
333 |
{
|
sl@0
|
334 |
addr.Get(from,fromsize);
|
sl@0
|
335 |
return ptr.Length();
|
sl@0
|
336 |
}
|
sl@0
|
337 |
}
|
sl@0
|
338 |
return MapError(err,anErrno);
|
sl@0
|
339 |
}
|
sl@0
|
340 |
|
sl@0
|
341 |
int CLocalSystemInterface::sendto (int fid, const char* buf, unsigned long len, int flags, struct sockaddr* to, unsigned long tosize, int& anErrno)
|
sl@0
|
342 |
{
|
sl@0
|
343 |
CFileDescBase* f=0;
|
sl@0
|
344 |
TInt err=iFids.Asynch(fid,f);
|
sl@0
|
345 |
if (!err)
|
sl@0
|
346 |
{
|
sl@0
|
347 |
TRequestStatus status;
|
sl@0
|
348 |
TPtr8 ptr((TText8 *)buf, len, len);
|
sl@0
|
349 |
TUSockAddr addr(to,tosize);
|
sl@0
|
350 |
f->SendTo(ptr,addr,flags,status);
|
sl@0
|
351 |
User::WaitForRequest(status);
|
sl@0
|
352 |
err=f->SendToCompletion(ptr, status.Int());
|
sl@0
|
353 |
f->Close(); // balances the Dup() in CFileTable::Asynch()
|
sl@0
|
354 |
if (err==0)
|
sl@0
|
355 |
return ptr.Length();
|
sl@0
|
356 |
}
|
sl@0
|
357 |
return MapError(err,anErrno);
|
sl@0
|
358 |
}
|
sl@0
|
359 |
|
sl@0
|
360 |
int CLocalSystemInterface::fsync (int fid, int& anErrno)
|
sl@0
|
361 |
{
|
sl@0
|
362 |
CFileDescBase* f=0;
|
sl@0
|
363 |
TInt err=iFids.Asynch(fid,f);
|
sl@0
|
364 |
if (!err)
|
sl@0
|
365 |
{
|
sl@0
|
366 |
TRequestStatus status;
|
sl@0
|
367 |
f->Sync(status);
|
sl@0
|
368 |
User::WaitForRequest(status);
|
sl@0
|
369 |
f->Close(); // balances the Dup() in CFileTable::Asynch()
|
sl@0
|
370 |
err=status.Int();
|
sl@0
|
371 |
}
|
sl@0
|
372 |
return MapError(err,anErrno);
|
sl@0
|
373 |
}
|
sl@0
|
374 |
|
sl@0
|
375 |
int CLocalSystemInterface::shutdown (int fid, int how, int& anErrno)
|
sl@0
|
376 |
{
|
sl@0
|
377 |
CFileDescBase* f=0;
|
sl@0
|
378 |
TInt err=iFids.Asynch(fid,f);
|
sl@0
|
379 |
if (!err)
|
sl@0
|
380 |
{
|
sl@0
|
381 |
TRequestStatus status;
|
sl@0
|
382 |
f->Shutdown(how,status);
|
sl@0
|
383 |
User::WaitForRequest(status);
|
sl@0
|
384 |
f->Close(); // balances the Dup() in CFileTable::Asynch()
|
sl@0
|
385 |
err=status.Int();
|
sl@0
|
386 |
}
|
sl@0
|
387 |
return MapError(err,anErrno);
|
sl@0
|
388 |
}
|
sl@0
|
389 |
|
sl@0
|
390 |
int CLocalSystemInterface::connect (int fid, struct sockaddr* addr, unsigned long size, int& anErrno)
|
sl@0
|
391 |
{
|
sl@0
|
392 |
CFileDescBase* f=0;
|
sl@0
|
393 |
TInt err=iFids.Asynch(fid,f);
|
sl@0
|
394 |
if (!err)
|
sl@0
|
395 |
{
|
sl@0
|
396 |
TRequestStatus status;
|
sl@0
|
397 |
TUSockAddr address(addr,size);
|
sl@0
|
398 |
f->Connect(address,status);
|
sl@0
|
399 |
User::WaitForRequest(status);
|
sl@0
|
400 |
f->Close(); // balances the Dup() in CFileTable::Asynch()
|
sl@0
|
401 |
err=status.Int();
|
sl@0
|
402 |
}
|
sl@0
|
403 |
return MapError(err,anErrno);
|
sl@0
|
404 |
}
|
sl@0
|
405 |
|
sl@0
|
406 |
int CLocalSystemInterface::accept (int fid, int& anErrno)
|
sl@0
|
407 |
//
|
sl@0
|
408 |
// The CSocketDesc performing the Accept is responsible for creating the new CSocketDesc
|
sl@0
|
409 |
//
|
sl@0
|
410 |
{
|
sl@0
|
411 |
CFileDescBase* f=0;
|
sl@0
|
412 |
TInt err=iFids.Asynch(fid,f);
|
sl@0
|
413 |
if (!err)
|
sl@0
|
414 |
{
|
sl@0
|
415 |
CSocketDesc* newf=0;
|
sl@0
|
416 |
int fd=iFids.Reserve();
|
sl@0
|
417 |
err=fd;
|
sl@0
|
418 |
if (fd>=0)
|
sl@0
|
419 |
{
|
sl@0
|
420 |
TRequestStatus status;
|
sl@0
|
421 |
f->Accept(newf,status,iSs);
|
sl@0
|
422 |
CleanupStack::PushL(newf);
|
sl@0
|
423 |
User::WaitForRequest(status);
|
sl@0
|
424 |
f->Close(); // balances the Dup() in CFileTable::Asynch()
|
sl@0
|
425 |
err=status.Int();
|
sl@0
|
426 |
if (!err)
|
sl@0
|
427 |
{
|
sl@0
|
428 |
err=iFids.Attach(fd,newf);
|
sl@0
|
429 |
if (!err)
|
sl@0
|
430 |
{
|
sl@0
|
431 |
CleanupStack::PopAndDestroy(newf);
|
sl@0
|
432 |
return fd;
|
sl@0
|
433 |
}
|
sl@0
|
434 |
}
|
sl@0
|
435 |
iFids.Attach(fd,0); // cancel the reservation
|
sl@0
|
436 |
CleanupStack::PopAndDestroy(newf);
|
sl@0
|
437 |
}
|
sl@0
|
438 |
}
|
sl@0
|
439 |
return MapError(err,anErrno);
|
sl@0
|
440 |
}
|
sl@0
|
441 |
|
sl@0
|
442 |
int CLocalSystemInterface::ioctl (int fid, int cmd, void* param, int& anErrno)
|
sl@0
|
443 |
{
|
sl@0
|
444 |
TRequestStatus ioctlStatus;
|
sl@0
|
445 |
TInt err=ioctl(fid,cmd,param,ioctlStatus,anErrno);
|
sl@0
|
446 |
if (err==KErrNone)
|
sl@0
|
447 |
{
|
sl@0
|
448 |
User::WaitForRequest(ioctlStatus);
|
sl@0
|
449 |
err=ioctl_complete(fid,cmd,param,ioctlStatus,anErrno);
|
sl@0
|
450 |
}
|
sl@0
|
451 |
return err;
|
sl@0
|
452 |
}
|
sl@0
|
453 |
|
sl@0
|
454 |
// C++ version of asynchronous ioctl
|
sl@0
|
455 |
|
sl@0
|
456 |
int CLocalSystemInterface::ioctl (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno)
|
sl@0
|
457 |
{
|
sl@0
|
458 |
CFileDescBase* f=0;
|
sl@0
|
459 |
TInt err=iFids.Asynch(fid,f);
|
sl@0
|
460 |
if (!err)
|
sl@0
|
461 |
{
|
sl@0
|
462 |
f->Ioctl(cmd,param,aStatus);
|
sl@0
|
463 |
f->Close(); // balances the Dup() in CFileTable::Asynch() - live dangerously!
|
sl@0
|
464 |
}
|
sl@0
|
465 |
return MapError(err,anErrno);
|
sl@0
|
466 |
}
|
sl@0
|
467 |
|
sl@0
|
468 |
int CLocalSystemInterface::ioctl_complete (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno)
|
sl@0
|
469 |
{
|
sl@0
|
470 |
return iFids.ioctlcomplete(fid,cmd,param,aStatus,anErrno);
|
sl@0
|
471 |
}
|
sl@0
|
472 |
|
sl@0
|
473 |
int CLocalSystemInterface::ioctl_cancel (int fid, int& anErrno)
|
sl@0
|
474 |
{
|
sl@0
|
475 |
return iFids.ioctlcancel(fid,anErrno);
|
sl@0
|
476 |
}
|