Cannot pass obj from server back to client
| Fri, 2007-02-16 16:52 | |
|
I want to pass a serialized object from the server back to the client (synchronously).
Here's my code. Code: /////////// CLIENT CODE /////////// void CMyClient::GetObjFromServerL() { iBuf = HBufC8::NewL(128); // 128 should be enough TPtr8 ptr(iBuf->Des()); TPckg<TDes8> payLoad(ptr); // iBuf should contain the // serialized obj // after the request is complete // but payLoad.Length == 8 // after this call! TIpcArgs args(&payLoad); User::LeaveIfError(SendReceive(EGetObj, args)); iObj->InternalizeL(ptr); // internalize iObj from iBuf } /////////// SERVER CODE /////////// void CMyServer::ProvideObj(const RMessage2& aMessage) { TInt msgLen = aMessage.GetDesLength(0); // msgLen == 8! that's not enough! HBufC8* buf = HBufC8::NewLC(iObj->Size()); TPtr8 ptr(buf->Des()); iObj->ExternalizeL(ptr); // externalize iObj into buf aMessage.WriteL(0, ptr); // <--- LEAVES WITH "OVERFLOW" (-9) CleanupStack::PopAndDestroy(buf); } Can somebody please tell me what's wrong here. What could be better? (Yes I know, I should use the non leaving overload of RMessage::Write - and than panic the client) regards Martin |
|






Forum posts: 1232
TPtr8 ptr(iBuf->Des());
TPckg<TDes8> payLoad(ptr); // iBuf should contain the
TIpcArgs args(&payLoad);
you are effectivly packageing a descriptor in a descriptor in a descriptor..
you should be able to do it simply by:
TIpcArgs args(iBuf);
And this also is behind your problem...
Forum posts: 1232
HBufC8 is a descriptor allocated on the heap, so a HBufC8* is already a pointer to a descriptor.
And a pointer to the descriptor is what the IPC wants.
when you then encapsulate it like this:
TPtr8 ptr(iBuf->Des());
you create a new descriptor, this one allocated on the stack. The descriptor it self will contain 1 pointer to the data and 1 integer length. This is total of 8 bytes.
The descriptor will though still point to the data you expect.
BUT
When you do this line:
TPckg<TDes8> payload(ptr);
you create yet another descriptor, this also allocated on the stack, but with storage space to store exactly one TDes8 descriptor (8 bytes, pointer + length)
The constructor also copies the data of the TPtr8 descriptor into the buffer.
You then tell IPC to use this descriptor by giving the pointer to it...
The server dereferncing this pointer will then get a pointer to the TPckg descriptor, wich holds only 8 bytes of data, the actual TDes8/TPtr8. And you have no way to reach the data that the TDes8/TPtr8 in the TPckg points too.
You need to give IPC the pointer to the descriptor you want the data in, not a pointer to a descriptor containing a descriptor you want the data in