-1

I am using ioctl() to read the number of characters in my buffer in a socket program. However at times, when populating of the buffer is delayed, it is misinterpreted by ioctl() as the end of the message. How can this be avoided if i were to use ioctl() to know the length of my incoming message. Also I do not know the size of the message that I would receive, hence I would not be able to receive it in a static buffer recv().

Thanks, Manoj

Manoj Kumar
  • 135
  • 1
  • 3
  • 13

1 Answers1

3

Make the message size part of the message preferabley the leading bytes. ie make first 2 bytes size of the rest of the message. This way you know you have to wait until 2 read bytes are read - then read size of message.

Adrian Cornish
  • 23,227
  • 13
  • 61
  • 77