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