sl@0
|
1 |
// Copyright (c) 1997-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 |
// Implementation of pipes
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include "POSIXIF.H"
|
sl@0
|
19 |
#include <sys/errno.h>
|
sl@0
|
20 |
#include <sys/stat.h>
|
sl@0
|
21 |
|
sl@0
|
22 |
// Child end of the pipe
|
sl@0
|
23 |
|
sl@0
|
24 |
CPipeChildDesc::CPipeChildDesc(TInt anIndex, RPosixSession& aSession)
|
sl@0
|
25 |
: CFileDescBase(), iIndex(anIndex), iSession(aSession), iParamDes(0,0,0)
|
sl@0
|
26 |
{}
|
sl@0
|
27 |
|
sl@0
|
28 |
TInt CPipeChildDesc::LSeek (int&, int)
|
sl@0
|
29 |
{
|
sl@0
|
30 |
return ESPIPE; // can't seek on a pipe
|
sl@0
|
31 |
}
|
sl@0
|
32 |
|
sl@0
|
33 |
TInt CPipeChildDesc::FStat(struct stat *st)
|
sl@0
|
34 |
{
|
sl@0
|
35 |
// I am a fifo about which little is known
|
sl@0
|
36 |
st->st_mode = S_IFIFO;
|
sl@0
|
37 |
st->st_blksize=0;
|
sl@0
|
38 |
return KErrNone;
|
sl@0
|
39 |
}
|
sl@0
|
40 |
|
sl@0
|
41 |
void CPipeChildDesc::Read (TDes8& aBuf, TRequestStatus& aStatus)
|
sl@0
|
42 |
{
|
sl@0
|
43 |
if (iClientClosed || !IsReadable())
|
sl@0
|
44 |
{
|
sl@0
|
45 |
Complete(aStatus,KErrEof);
|
sl@0
|
46 |
return;
|
sl@0
|
47 |
}
|
sl@0
|
48 |
TIpcArgs args(iIndex,&aBuf,aBuf.MaxLength());
|
sl@0
|
49 |
iSession.Request(PMPipeRead,args,aStatus); // asynchronous request
|
sl@0
|
50 |
}
|
sl@0
|
51 |
|
sl@0
|
52 |
void CPipeChildDesc::ReadCancel()
|
sl@0
|
53 |
{
|
sl@0
|
54 |
Cancel(PMPipeRead);
|
sl@0
|
55 |
}
|
sl@0
|
56 |
|
sl@0
|
57 |
TInt CPipeChildDesc::ReadCompletion(TDes8& aDesc, TInt aStatus)
|
sl@0
|
58 |
{
|
sl@0
|
59 |
if (aStatus==KErrEof)
|
sl@0
|
60 |
{
|
sl@0
|
61 |
ClientClose();
|
sl@0
|
62 |
aDesc.Zero(); // set read length to zero
|
sl@0
|
63 |
return KErrNone; // indicates graceful close at the other end
|
sl@0
|
64 |
}
|
sl@0
|
65 |
return aStatus;
|
sl@0
|
66 |
}
|
sl@0
|
67 |
|
sl@0
|
68 |
void CPipeChildDesc::Write(TDes8& aDesc, TRequestStatus& aStatus)
|
sl@0
|
69 |
{
|
sl@0
|
70 |
if (iClientClosed || !IsWriteable())
|
sl@0
|
71 |
{
|
sl@0
|
72 |
Complete(aStatus,KErrEof);
|
sl@0
|
73 |
return;
|
sl@0
|
74 |
}
|
sl@0
|
75 |
TIpcArgs args(iIndex,&aDesc,aDesc.Length());
|
sl@0
|
76 |
iSession.Request(PMPipeWrite,args,aStatus); // asynchronous request
|
sl@0
|
77 |
}
|
sl@0
|
78 |
|
sl@0
|
79 |
void CPipeChildDesc::WriteCancel()
|
sl@0
|
80 |
{
|
sl@0
|
81 |
Cancel(PMPipeWrite);
|
sl@0
|
82 |
}
|
sl@0
|
83 |
|
sl@0
|
84 |
TInt CPipeChildDesc::WriteCompletion(TDes8& /*aDesc*/, TInt aStatus)
|
sl@0
|
85 |
{
|
sl@0
|
86 |
if (aStatus==KErrEof)
|
sl@0
|
87 |
ClientClose();
|
sl@0
|
88 |
return aStatus;
|
sl@0
|
89 |
}
|
sl@0
|
90 |
|
sl@0
|
91 |
void CPipeChildDesc::Ioctl(int aCmd, void* aParam, TRequestStatus& aStatus)
|
sl@0
|
92 |
//
|
sl@0
|
93 |
// The work of the Ioctl is done in the parent, including writing back to aParam?
|
sl@0
|
94 |
// Use the default completion which just returns aStatus.Int()
|
sl@0
|
95 |
//
|
sl@0
|
96 |
{
|
sl@0
|
97 |
if (iClientClosed)
|
sl@0
|
98 |
{
|
sl@0
|
99 |
Complete(aStatus,KErrEof);
|
sl@0
|
100 |
return;
|
sl@0
|
101 |
}
|
sl@0
|
102 |
iParamDes.Set((TText8*)aParam,4,4);
|
sl@0
|
103 |
TIpcArgs args(iIndex,aCmd,&iParamDes);
|
sl@0
|
104 |
if (aCmd==E32IOSELECT)
|
sl@0
|
105 |
args.Set(3, *((TInt*)aParam));
|
sl@0
|
106 |
iSession.Request(PMPipeIoctl,args,aStatus); // asynchronous request
|
sl@0
|
107 |
}
|
sl@0
|
108 |
|
sl@0
|
109 |
void CPipeChildDesc::IoctlCancel()
|
sl@0
|
110 |
{
|
sl@0
|
111 |
Cancel(PMPipeIoctl);
|
sl@0
|
112 |
}
|
sl@0
|
113 |
|
sl@0
|
114 |
void CPipeChildDesc::Cancel(TInt aType)
|
sl@0
|
115 |
{
|
sl@0
|
116 |
if (iClientClosed)
|
sl@0
|
117 |
return;
|
sl@0
|
118 |
TIpcArgs args(iIndex,aType);
|
sl@0
|
119 |
iSession.Request(PMPipeCancel,args);
|
sl@0
|
120 |
}
|
sl@0
|
121 |
|
sl@0
|
122 |
TInt CPipeChildDesc::FinalClose()
|
sl@0
|
123 |
{
|
sl@0
|
124 |
ClientClose();
|
sl@0
|
125 |
TIpcArgs args(iIndex);
|
sl@0
|
126 |
return iSession.Request(PMPipeClose,args); // synchronous request
|
sl@0
|
127 |
}
|
sl@0
|
128 |
|
sl@0
|
129 |
//
|
sl@0
|
130 |
// Parent end of the pipe, where the real work is done
|
sl@0
|
131 |
//
|
sl@0
|
132 |
|
sl@0
|
133 |
CPipeDesc::CPipeDesc(TInt anIndex) : CFileDescBase()
|
sl@0
|
134 |
{
|
sl@0
|
135 |
iIndex=anIndex;
|
sl@0
|
136 |
}
|
sl@0
|
137 |
|
sl@0
|
138 |
void CPipeDesc::SetClientSide(CPipeDesc*& aClientPointer)
|
sl@0
|
139 |
{
|
sl@0
|
140 |
iClientSide=&aClientPointer;
|
sl@0
|
141 |
}
|
sl@0
|
142 |
|
sl@0
|
143 |
_LIT(KCPipeDescPanic, "CPipeDesc");
|
sl@0
|
144 |
void CPipeDesc::Panic(TInt aReason)
|
sl@0
|
145 |
{
|
sl@0
|
146 |
User::Panic(KCPipeDescPanic,aReason);
|
sl@0
|
147 |
}
|
sl@0
|
148 |
|
sl@0
|
149 |
void CPipeDesc::Panic(RMessage2& aMessage, TInt aReason)
|
sl@0
|
150 |
{
|
sl@0
|
151 |
aMessage.Panic(KCPipeDescPanic,aReason);
|
sl@0
|
152 |
}
|
sl@0
|
153 |
|
sl@0
|
154 |
TInt CPipeDesc::LSeek (int&, int)
|
sl@0
|
155 |
{
|
sl@0
|
156 |
return ESPIPE; // can't seek on a pipe
|
sl@0
|
157 |
}
|
sl@0
|
158 |
|
sl@0
|
159 |
TInt CPipeDesc::FStat(struct stat *st)
|
sl@0
|
160 |
{
|
sl@0
|
161 |
// I am a fifo about which little is known
|
sl@0
|
162 |
st->st_mode = S_IFIFO;
|
sl@0
|
163 |
st->st_blksize=0;
|
sl@0
|
164 |
return KErrNone;
|
sl@0
|
165 |
}
|
sl@0
|
166 |
|
sl@0
|
167 |
void CPipeDesc::Read (TDes8& aBuf, TRequestStatus& aStatus)
|
sl@0
|
168 |
{
|
sl@0
|
169 |
if (!IsReadable())
|
sl@0
|
170 |
{
|
sl@0
|
171 |
Complete(aStatus, KErrEof); // avoids treading on iStatus of pending Write
|
sl@0
|
172 |
return;
|
sl@0
|
173 |
}
|
sl@0
|
174 |
__ASSERT_DEBUG(iStatus==0,Panic(1));
|
sl@0
|
175 |
iStatus=&aStatus;
|
sl@0
|
176 |
if (iClientClosed)
|
sl@0
|
177 |
{
|
sl@0
|
178 |
User::RequestComplete(iStatus,KErrEof);
|
sl@0
|
179 |
return;
|
sl@0
|
180 |
}
|
sl@0
|
181 |
iReadBuf=&aBuf;
|
sl@0
|
182 |
if (ClientIoctlPending())
|
sl@0
|
183 |
CompleteClientIoctl();
|
sl@0
|
184 |
if (iClientLength!=0)
|
sl@0
|
185 |
TransferFromClient();
|
sl@0
|
186 |
}
|
sl@0
|
187 |
|
sl@0
|
188 |
void CPipeDesc::ReadCancel()
|
sl@0
|
189 |
{
|
sl@0
|
190 |
Cancel();
|
sl@0
|
191 |
}
|
sl@0
|
192 |
|
sl@0
|
193 |
TInt CPipeDesc::ReadCompletion(TDes8& aDesc, TInt aStatus)
|
sl@0
|
194 |
{
|
sl@0
|
195 |
if (aStatus==KErrEof)
|
sl@0
|
196 |
{
|
sl@0
|
197 |
ClientClose();
|
sl@0
|
198 |
aDesc.Zero(); // set read length to zero
|
sl@0
|
199 |
return KErrNone; // indicates graceful close at the other end
|
sl@0
|
200 |
}
|
sl@0
|
201 |
return aStatus;
|
sl@0
|
202 |
}
|
sl@0
|
203 |
|
sl@0
|
204 |
void CPipeDesc::Write(TDes8& aDesc, TRequestStatus& aStatus)
|
sl@0
|
205 |
{
|
sl@0
|
206 |
if (!IsWriteable())
|
sl@0
|
207 |
{
|
sl@0
|
208 |
Complete(aStatus, KErrEof); // avoids treading on iStatus of pending Read
|
sl@0
|
209 |
return;
|
sl@0
|
210 |
}
|
sl@0
|
211 |
__ASSERT_DEBUG(iStatus==0,Panic(2));
|
sl@0
|
212 |
iStatus=&aStatus;
|
sl@0
|
213 |
if (iClientClosed)
|
sl@0
|
214 |
{
|
sl@0
|
215 |
User::RequestComplete(iStatus,KErrEof);
|
sl@0
|
216 |
return;
|
sl@0
|
217 |
}
|
sl@0
|
218 |
iWriteBuf.Set(aDesc);
|
sl@0
|
219 |
if (ClientIoctlPending())
|
sl@0
|
220 |
CompleteClientIoctl();
|
sl@0
|
221 |
if (iClientLength!=0)
|
sl@0
|
222 |
TransferToClient();
|
sl@0
|
223 |
}
|
sl@0
|
224 |
|
sl@0
|
225 |
void CPipeDesc::WriteCancel()
|
sl@0
|
226 |
{
|
sl@0
|
227 |
Cancel();
|
sl@0
|
228 |
}
|
sl@0
|
229 |
|
sl@0
|
230 |
TInt CPipeDesc::WriteCompletion(TDes8& /*aDesc*/, TInt aStatus)
|
sl@0
|
231 |
{
|
sl@0
|
232 |
if (aStatus==KErrEof)
|
sl@0
|
233 |
ClientClose();
|
sl@0
|
234 |
return aStatus;
|
sl@0
|
235 |
}
|
sl@0
|
236 |
|
sl@0
|
237 |
void CPipeDesc::Ioctl(int aCmd, void* aParam, TRequestStatus& aStatus)
|
sl@0
|
238 |
{
|
sl@0
|
239 |
TInt ret=KErrNone;
|
sl@0
|
240 |
iIoctlStatus=&aStatus;
|
sl@0
|
241 |
int *param=REINTERPRET_CAST(int*,aParam);
|
sl@0
|
242 |
switch (aCmd)
|
sl@0
|
243 |
{
|
sl@0
|
244 |
case E32IONREAD:
|
sl@0
|
245 |
// synchronous ioctls are handled in the completion routine.
|
sl@0
|
246 |
break;
|
sl@0
|
247 |
case E32IOSELECT:
|
sl@0
|
248 |
{
|
sl@0
|
249 |
int mask=(*param)&SelectMask();
|
sl@0
|
250 |
if (mask!=0 && iClientLength==0)
|
sl@0
|
251 |
return; // wait for client to show up
|
sl@0
|
252 |
}
|
sl@0
|
253 |
break;
|
sl@0
|
254 |
default:
|
sl@0
|
255 |
ret=KErrNotSupported;
|
sl@0
|
256 |
break;
|
sl@0
|
257 |
}
|
sl@0
|
258 |
User::RequestComplete(iIoctlStatus,ret);
|
sl@0
|
259 |
}
|
sl@0
|
260 |
|
sl@0
|
261 |
TInt CPipeDesc::IoctlCompletion(int aCmd, void* aParam, TInt aStatus)
|
sl@0
|
262 |
{
|
sl@0
|
263 |
TInt ret=aStatus;
|
sl@0
|
264 |
if (ret!=KErrNone)
|
sl@0
|
265 |
return ret;
|
sl@0
|
266 |
int *param=REINTERPRET_CAST(int*,aParam);
|
sl@0
|
267 |
switch (aCmd)
|
sl@0
|
268 |
{
|
sl@0
|
269 |
case E32IONREAD:
|
sl@0
|
270 |
if (IsReadable())
|
sl@0
|
271 |
*param=iClientLength; // 0 if no outstanding client data
|
sl@0
|
272 |
else
|
sl@0
|
273 |
*param=0; // claim that no data is available
|
sl@0
|
274 |
break;
|
sl@0
|
275 |
case E32IOSELECT:
|
sl@0
|
276 |
{
|
sl@0
|
277 |
int mask=0;
|
sl@0
|
278 |
if (iClientLength!=0)
|
sl@0
|
279 |
mask = SelectMask();
|
sl@0
|
280 |
*param=(*param)&mask;
|
sl@0
|
281 |
}
|
sl@0
|
282 |
break;
|
sl@0
|
283 |
default:
|
sl@0
|
284 |
ret=KErrNotSupported;
|
sl@0
|
285 |
break;
|
sl@0
|
286 |
}
|
sl@0
|
287 |
return ret;
|
sl@0
|
288 |
}
|
sl@0
|
289 |
|
sl@0
|
290 |
void CPipeDesc::IoctlCancel()
|
sl@0
|
291 |
{
|
sl@0
|
292 |
User::RequestComplete(iIoctlStatus,KErrCancel);
|
sl@0
|
293 |
}
|
sl@0
|
294 |
|
sl@0
|
295 |
void CPipeDesc::Cancel()
|
sl@0
|
296 |
{
|
sl@0
|
297 |
// Pipes are unidirectional, so don't need to distinguish between
|
sl@0
|
298 |
// ReadCancel and WriteCancel
|
sl@0
|
299 |
User::RequestComplete(iStatus,KErrCancel);
|
sl@0
|
300 |
}
|
sl@0
|
301 |
|
sl@0
|
302 |
// Client-side interface
|
sl@0
|
303 |
|
sl@0
|
304 |
void CPipeDesc::ClientWrite(const RMessage2& aMessage)
|
sl@0
|
305 |
{
|
sl@0
|
306 |
__ASSERT_DEBUG(iClientLength==0,Panic(3));
|
sl@0
|
307 |
if (iClientClosed)
|
sl@0
|
308 |
{
|
sl@0
|
309 |
aMessage.Complete(KErrEof);
|
sl@0
|
310 |
return;
|
sl@0
|
311 |
}
|
sl@0
|
312 |
iClientLength=aMessage.Int2();
|
sl@0
|
313 |
iClientOffset=0;
|
sl@0
|
314 |
iMessage=aMessage;
|
sl@0
|
315 |
if (iIoctlStatus!=0)
|
sl@0
|
316 |
User::RequestComplete(iIoctlStatus,KErrNone);
|
sl@0
|
317 |
if (iStatus!=0)
|
sl@0
|
318 |
TransferFromClient();
|
sl@0
|
319 |
}
|
sl@0
|
320 |
|
sl@0
|
321 |
void CPipeDesc::ClientRead(const RMessage2& aMessage)
|
sl@0
|
322 |
{
|
sl@0
|
323 |
__ASSERT_DEBUG(iClientLength==0,Panic(4));
|
sl@0
|
324 |
if (iClientClosed)
|
sl@0
|
325 |
{
|
sl@0
|
326 |
aMessage.Complete(KErrEof);
|
sl@0
|
327 |
return;
|
sl@0
|
328 |
}
|
sl@0
|
329 |
iClientLength=aMessage.Int2();
|
sl@0
|
330 |
iMessage=aMessage;
|
sl@0
|
331 |
if (iIoctlStatus!=0)
|
sl@0
|
332 |
User::RequestComplete(iIoctlStatus,KErrNone);
|
sl@0
|
333 |
if (iStatus!=0)
|
sl@0
|
334 |
TransferToClient();
|
sl@0
|
335 |
}
|
sl@0
|
336 |
|
sl@0
|
337 |
void CPipeDesc::ClientIoctl(const RMessage2& aMessage)
|
sl@0
|
338 |
{
|
sl@0
|
339 |
__ASSERT_DEBUG(!ClientIoctlPending(),Panic(7));
|
sl@0
|
340 |
if (iClientClosed)
|
sl@0
|
341 |
{
|
sl@0
|
342 |
aMessage.Complete(KErrEof);
|
sl@0
|
343 |
return;
|
sl@0
|
344 |
}
|
sl@0
|
345 |
iClientIoctlPending=1;
|
sl@0
|
346 |
iIoctlMessage=aMessage;
|
sl@0
|
347 |
TInt ret=KErrNone;
|
sl@0
|
348 |
switch (aMessage.Int1())
|
sl@0
|
349 |
{
|
sl@0
|
350 |
case E32IONREAD:
|
sl@0
|
351 |
// synchronous ioctls are handled in the completion routine.
|
sl@0
|
352 |
break;
|
sl@0
|
353 |
case E32IOSELECT:
|
sl@0
|
354 |
{
|
sl@0
|
355 |
int mask=aMessage.Int3();
|
sl@0
|
356 |
mask&=ClientSelectMask();
|
sl@0
|
357 |
if (mask!=0 && iStatus==0)
|
sl@0
|
358 |
return; // wait for parent activity
|
sl@0
|
359 |
}
|
sl@0
|
360 |
break;
|
sl@0
|
361 |
default:
|
sl@0
|
362 |
ret=KErrNotSupported;
|
sl@0
|
363 |
break;
|
sl@0
|
364 |
}
|
sl@0
|
365 |
CompleteClientIoctl(ret);
|
sl@0
|
366 |
}
|
sl@0
|
367 |
|
sl@0
|
368 |
void CPipeDesc::ClientCancel(const RMessage2& aMessage)
|
sl@0
|
369 |
{
|
sl@0
|
370 |
if (aMessage.Int1()==PMPipeIoctl)
|
sl@0
|
371 |
{
|
sl@0
|
372 |
if (ClientIoctlPending())
|
sl@0
|
373 |
CompleteClientIoctl(KErrCancel);
|
sl@0
|
374 |
return;
|
sl@0
|
375 |
}
|
sl@0
|
376 |
// Pipes are unidirectional, so Read and Write are cancelled by
|
sl@0
|
377 |
// cancelling the current client operation.
|
sl@0
|
378 |
//
|
sl@0
|
379 |
if (iClientLength!=0)
|
sl@0
|
380 |
{
|
sl@0
|
381 |
iMessage.Complete(KErrCancel);
|
sl@0
|
382 |
iClientLength=0;
|
sl@0
|
383 |
}
|
sl@0
|
384 |
}
|
sl@0
|
385 |
|
sl@0
|
386 |
void CPipeDesc::ClientClose()
|
sl@0
|
387 |
{
|
sl@0
|
388 |
iClientClosed=1;
|
sl@0
|
389 |
// terminate any pending requests
|
sl@0
|
390 |
if (iStatus!=0)
|
sl@0
|
391 |
User::RequestComplete(iStatus,KErrEof);
|
sl@0
|
392 |
if (ClientIoctlPending())
|
sl@0
|
393 |
CompleteClientIoctl(KErrEof);
|
sl@0
|
394 |
if (iClientLength!=0)
|
sl@0
|
395 |
{
|
sl@0
|
396 |
iMessage.Complete(KErrEof);
|
sl@0
|
397 |
iClientLength=0;
|
sl@0
|
398 |
}
|
sl@0
|
399 |
}
|
sl@0
|
400 |
|
sl@0
|
401 |
TInt CPipeDesc::FinalClose()
|
sl@0
|
402 |
{
|
sl@0
|
403 |
ClientClose();
|
sl@0
|
404 |
if (iClientSide)
|
sl@0
|
405 |
{
|
sl@0
|
406 |
*iClientSide=0;
|
sl@0
|
407 |
iClientSide=0;
|
sl@0
|
408 |
}
|
sl@0
|
409 |
return KErrNone;
|
sl@0
|
410 |
}
|
sl@0
|
411 |
|
sl@0
|
412 |
void CPipeDesc::TransferFromClient()
|
sl@0
|
413 |
//
|
sl@0
|
414 |
// Handle transfer of data from client to parent.
|
sl@0
|
415 |
// Always complete the parent read, but only complete the child write when
|
sl@0
|
416 |
// all of the data has been consumed.
|
sl@0
|
417 |
//
|
sl@0
|
418 |
{
|
sl@0
|
419 |
TRAPD(err,iMessage.ReadL(1,*iReadBuf,iClientOffset));
|
sl@0
|
420 |
if (err)
|
sl@0
|
421 |
{
|
sl@0
|
422 |
Panic(iMessage,5);
|
sl@0
|
423 |
iClientLength=0;
|
sl@0
|
424 |
ClientClose(); // will complete the parent read
|
sl@0
|
425 |
return;
|
sl@0
|
426 |
}
|
sl@0
|
427 |
TInt length=iReadBuf->Length(); // record the amount of data transferred
|
sl@0
|
428 |
User::RequestComplete(iStatus,KErrNone);
|
sl@0
|
429 |
iClientOffset+=length;
|
sl@0
|
430 |
iClientLength-=length;
|
sl@0
|
431 |
if (iClientLength==0)
|
sl@0
|
432 |
iMessage.Complete(KErrNone);
|
sl@0
|
433 |
}
|
sl@0
|
434 |
|
sl@0
|
435 |
void CPipeDesc::TransferToClient()
|
sl@0
|
436 |
//
|
sl@0
|
437 |
// Handle transfer from parent to client
|
sl@0
|
438 |
// Always complete the client read, but only complete the parent write when
|
sl@0
|
439 |
// all of the data has been consumed.
|
sl@0
|
440 |
//
|
sl@0
|
441 |
{
|
sl@0
|
442 |
TInt err=KErrNone;
|
sl@0
|
443 |
TInt length=iWriteBuf.Length();
|
sl@0
|
444 |
TInt written=length;
|
sl@0
|
445 |
if (iClientLength >= length)
|
sl@0
|
446 |
{
|
sl@0
|
447 |
TRAP(err,iMessage.WriteL(1,iWriteBuf,0));
|
sl@0
|
448 |
}
|
sl@0
|
449 |
else
|
sl@0
|
450 |
{
|
sl@0
|
451 |
written=iClientLength;
|
sl@0
|
452 |
TRAP(err,iMessage.WriteL(1,iWriteBuf.Left(written),0));
|
sl@0
|
453 |
}
|
sl@0
|
454 |
iClientLength=0;
|
sl@0
|
455 |
if (err)
|
sl@0
|
456 |
{
|
sl@0
|
457 |
Panic(iMessage,6);
|
sl@0
|
458 |
ClientClose(); // will complete the parent write
|
sl@0
|
459 |
return;
|
sl@0
|
460 |
}
|
sl@0
|
461 |
iMessage.Complete(KErrNone);
|
sl@0
|
462 |
length-=written;
|
sl@0
|
463 |
if (length==0)
|
sl@0
|
464 |
User::RequestComplete(iStatus,KErrNone);
|
sl@0
|
465 |
else
|
sl@0
|
466 |
iWriteBuf.Set(iWriteBuf.Right(length));
|
sl@0
|
467 |
}
|
sl@0
|
468 |
|
sl@0
|
469 |
void CPipeDesc::CompleteClientIoctl(TInt ret)
|
sl@0
|
470 |
{
|
sl@0
|
471 |
if (ret!=KErrNone)
|
sl@0
|
472 |
{
|
sl@0
|
473 |
iIoctlMessage.Complete(ret);
|
sl@0
|
474 |
iClientIoctlPending=0;
|
sl@0
|
475 |
return;
|
sl@0
|
476 |
}
|
sl@0
|
477 |
CompleteClientIoctl();
|
sl@0
|
478 |
}
|
sl@0
|
479 |
|
sl@0
|
480 |
void CPipeDesc::CompleteClientIoctl()
|
sl@0
|
481 |
//
|
sl@0
|
482 |
// Complete outstanding PMPipeIoctl message
|
sl@0
|
483 |
//
|
sl@0
|
484 |
{
|
sl@0
|
485 |
TInt ret=KErrNone;
|
sl@0
|
486 |
int param=0;
|
sl@0
|
487 |
switch (iIoctlMessage.Int1())
|
sl@0
|
488 |
{
|
sl@0
|
489 |
case E32IONREAD:
|
sl@0
|
490 |
if (IsWriteable() && iStatus!=0)
|
sl@0
|
491 |
param=iWriteBuf.Length();
|
sl@0
|
492 |
else
|
sl@0
|
493 |
param=0; // claim that no data is available
|
sl@0
|
494 |
break;
|
sl@0
|
495 |
case E32IOSELECT:
|
sl@0
|
496 |
{
|
sl@0
|
497 |
int mask=0;
|
sl@0
|
498 |
if (iStatus!=0)
|
sl@0
|
499 |
mask=ClientSelectMask();
|
sl@0
|
500 |
param=(iIoctlMessage.Int3())&mask;
|
sl@0
|
501 |
}
|
sl@0
|
502 |
break;
|
sl@0
|
503 |
default:
|
sl@0
|
504 |
ret=KErrNotSupported;
|
sl@0
|
505 |
break;
|
sl@0
|
506 |
}
|
sl@0
|
507 |
if (ret==KErrNone)
|
sl@0
|
508 |
{
|
sl@0
|
509 |
TPtrC8 paramReturn((const TText8*)¶m,4);
|
sl@0
|
510 |
TRAP(ret,iIoctlMessage.WriteL(2,paramReturn,0));
|
sl@0
|
511 |
}
|
sl@0
|
512 |
iIoctlMessage.Complete(ret);
|
sl@0
|
513 |
iClientIoctlPending=0;
|
sl@0
|
514 |
}
|