×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Regular Contributor
    Join Date
    Mar 2008
    Posts
    60

    Transfering Heap buffers over IPC

    Hello!

    I have a server with its sessions (from CServer2 and CSession2) and I want to transfer the pointer to some large heap buffer to and from the client.

    I already know that I have to package it somehow into the RMessage2 but since I'm not so good on descriptors, I don't really know how to start.

    The easiest solution I could think of would be to allocate the buffer on the heap and than pass the address as an integer argument. I know it's not very clean, buf would it work?

    Can someone please help me??
    Last edited by mg_at_uni; 2008-09-02 at 10:33.

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,751

    Re: Transfering Heap buffers over IPC

    You can do some magic with shared memory (using RChunk and RHeap), if you search for RChunk, in the SDK Help, there will be some hints in the "Publish & Subscribe" hit.

  3. #3
    Regular Contributor
    Join Date
    Mar 2008
    Posts
    60

    Re: Transfering Heap buffers over IPC

    Thanks for the hint.

    But I don't get it working. How can I allocate memory so that the pointer is valid in another process?
    Perhaps you could give or point me to a small example!

    Thanks a lot!

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    16

    Re: Transfering Heap buffers over IPC

    On client side, if it wants read data from the server, it should allocate a buffer, and transfer the address of the TPtr8, for example, in RYourClientSession class, in your method.
    HBufC8* buf = HBufC8::NewLC( 100 );
    TPtr8 bufPtr( buf->Des() );
    SendReceive( EYourFuncId, TIpcArgs( &bufPtr ) );

    On server side, if it has a parameter "aMessage".
    aMessage.WriteL( 0, KSomeData );
    aMessage.Complete( KErrNone );

    If you want transfer some data to the server.
    On client side,
    HBufC8* yourData; SendReceive( EYourFuncId, TIpcArgs( yourData ) );

    On server side, you must allocate a new buffer to store the data. The buffer length can be gotten via RMessage2::GetDesLengthL( 0 ). Read content using RMessage2::Read().

  5. #5
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,751

    Re: Transfering Heap buffers over IPC

    Quote Originally Posted by mg_at_uni View Post
    How can I allocate memory so that the pointer is valid in another process?
    What you can do instead is using RChunk::Base. The returned pointers may have different values in the different processes, but they will point to the same content or "memory".

    Victor: the thread is about not using IPC with descriptors.

  6. #6
    Regular Contributor
    Join Date
    Mar 2008
    Posts
    60

    Re: Transfering Heap buffers over IPC

    Thanks victor for your example! I will try if I get it running.

    @wizard:
    Base() returns the base address of the memory region. So how would I use that?

    Code:
    _LIT(KChunkName, "ChunkName");
    
    RChunk myChunk;
    RHeap * myHeap;
    
    myChunk.CreateGlobal(KChunkName, 5000, 5000);
    myHeap = User::ChunkHeap( myChunk, 5000 );
    	
    TPtr8 ptr ((TUint8*)myHeap->Alloc( 5000 ), 5000);
    
    SendReceive( EYourFuncId, TIpcArgs( myChunk.Base() ) );
    Does that work? And what would I have to do on server side?

    Thanks very much!

  7. #7
    Regular Contributor
    Join Date
    Mar 2008
    Posts
    60

    Re: Transfering Heap buffers over IPC

    Problem solved!
    I got it running with victors example. Thank you both for your help!

    Just to complete this topic, here's what I've try and what worked:

    Sending data from the client to the server:
    Client:
    Code:
    void RServSession::SendData()
    {
    	_LIT8(KTest, "1234567890123456789012345678901234567890");
    
    	HBufC8* theData = HBufC8::NewLC(50);
    	*theData = KTest;
    	SendReceive(EMyFuncID, TIpcArgs(theData));
    }
    Server (handler function that is call by DispatchMessageL):
    Code:
    void CServSession::SendData(const RMessage2& aMessage)
    {
    	// Create a buffer with the neccessary size
    	HBufC8 *buffer = HBufC8::NewL(aMessage.GetDesLengthL(0));
    
    	TPtr8 ptr (buffer->Des());
    	aMessage.Read(0, ptr);
    
    	// Data is now copied to buffer resp. ptr
    }

    Sending data from the server to the client:
    Client:
    Code:
    void RServSession::GetData()
    {
    	HBufC8* buf = HBufC8::NewLC( 1000 );
    	TPtr8 bufPtr( buf->Des() );
    	SendReceive( EServiceServGet, TIpcArgs( &bufPtr ) );
    
    	// Data from server is now stored in buf resp bufPtr
    
    }
    Server:
    Code:
    void CServSession::GetData(const RMessage2& aMessage)
    {
    	_LIT8(KSomeData, "Some server data for the client");
    	aMessage.WriteL( 0, KSomeData );
    }

Similar Threads

  1. Problem with eglSwapBuffers and heap corruption
    By greatape in forum Symbian Media (Closed)
    Replies: 2
    Last Post: 2007-05-24, 03:35
  2. 3rd ed emulator heap size
    By apsaarin in forum Symbian Tools & SDKs
    Replies: 7
    Last Post: 2007-03-15, 02:29
  3. info about heap size
    By gmatkar in forum Mobile Java General
    Replies: 5
    Last Post: 2006-03-10, 04:05
  4. what is considered heap?
    By dannyai in forum Mobile Java General
    Replies: 8
    Last Post: 2003-07-16, 08:02
  5. Replies: 0
    Last Post: 2003-06-13, 15:23

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×