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.
Any help is appreciated.