简体   繁体   中英

ioctl() for socket programming in C

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM