Hope you are doing well. I am facing a serious allocation problem. I try to create a buffer of variable size using following call.
iDynamicBuffer = HBufC8::NewL(iBufferLen);
TDes8 *des = &iDynamicBuffer->Des();
i = des->MaxSize(); // always rounded to 4
i = des->MaxLength() // always rounded to 4
However whatever may be the value of iBufferLen I always get the return value rounded up to next 4 byte boundary. I accepted this and tried to work around with it. But then inconsistently the system started returning me more bytes then I am requesting. For example if I ask for 120 bytes it returns me 124 bytes sometime but not always. The problem is that I am using socket calls and I only want to read 120 bytes, but since the buffer size sometime becomes 124 and if network has 124 bytes available then it returns 124 bytes or if it doesnt have then it just waits for 124 bytes to arrive. My system wants that the socket read should return whenever it has read a particular amount of data e.g. 120. Any clue why it is happening. RecvOneOrMore is also a problem because of this behaviour because it may also return 124 sometimes. There is no way of specifying size in the socket reads except that the size comes from the MaxLength of the buffer.
Anyone have any ideas? I'm running into this too. I hacked around it by making my sender pad all transfers to even multiples of 4, but there's gotta be a better way!
yep, it's very annoying and haven't really seen solution for it.
Anyway as a workaround I used to use two step communication method, first reading the header of the incoming data and then the data itself.
The header is small and always same size, so I can use TBuf8 type of buffer for it. then when I know the size of the incoming data so can make Hbuf8 for it and just call RecvOneOrMore() as meny times as I need to get all the data that I need.
If you are reading from a socket try to read with a constant TBuf8 and then insert into a CBufFlat. I'm doing that way and it works ok. Just try to set granularity equal to TBuf8 length.