×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    30

    Question RSocket::Write corrupts stack

    Dear experts,

    I use and adapt the EchoWrite example from the SDK examples and need to transfer data three times in a row. My problem is that RSocket::Write() which is fed with a pointer to my data, overwrites this data before the AO actually transfers the data, so my server receives the corrupted data. This doesn't happen with the first transfer, but only with the second.

    I use the AO CEchoWrite. IssueWrite() is always fed with pointer to the data and dataSize:


    void CEchoWrite::IssueWrite(const unsigned int dataSize, char const * const data)
    {
    TPtrC8 *desc= new TPtrC8((TUint8*)data, (TInt)dataSize);
    iEchoSocket->Write(desc, iStatus);
    iTimer->After(iTimeOut);
    SetActive();
    };


    In RunL() I check if iStatus is KErrNone and proceed by calling IssueWrite() once more to send the second data packet. Using the debugger, I notice that right before calling Write(), desc->iPtr points to the correct data which is part of the stack -- several steps higher, at a platform independent level, the network handling class declares some local data as char[], fills the data with the proper content and calls lower layers which eventually calls the AO to send the data.

    One step beyond, desc->iPtr still points to the same memory but the contents of the memory have changed! Most intriguingly, sending the same data twice, it runs perfectly for the first time, but only corrupts the data at the second call of IssueWrite().

    A quick test allocating the data from the heap using 'new char[n]' seems to work.

    Any suggestions? No other AOs are active, the layer which puts the data onto the stack is not reached in the meantime.

  2. #2
    Registered User
    Join Date
    May 2007
    Location
    Poland
    Posts
    606

    Re: RSocket::Write corrupts stack

    Hello,
    using local variables in asyncrhonous functions is not recommended.

    Make TPtrC8 *desc global and share your results.

    good luck

  3. #3
    Regular Contributor
    Join Date
    Apr 2008
    Posts
    146

    Re: RSocket::Write corrupts stack

    Quote Originally Posted by nuker85 View Post
    Hello,
    using local variables in asyncrhonous functions is not recommended.
    True, mildly said...

    Quote Originally Posted by nuker85 View Post
    Make TPtrC8 *desc global and share your results.
    Better to make it a member variable of the class, than a global variable.

    Quote Originally Posted by nuker85 View Post
    good luck
    The same.

Similar Threads

  1. FATAL ERROR - Applet 17 with certain png's
    By OneNineStudios in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2008-12-17, 13:11
  2. Conflicting stack sizes - again!
    By schm1 in forum Mobile Java General
    Replies: 7
    Last Post: 2005-10-08, 12:09
  3. Stack and scope
    By torui in forum Symbian
    Replies: 1
    Last Post: 2005-03-01, 10:44
  4. Replies: 0
    Last Post: 2004-03-03, 20:49

Posting Permissions

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