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);
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.