Linux - ioctl with FIONREAD always 0

后端 未结 5 1371
滥情空心
滥情空心 2021-02-05 13:02

I\'m trying to get to know how many bytes there are readable at my TCP socket. I am calling ioctl with the Flag \"FIONREAD\" which should actually give me this value. When I ca

5条回答
  •  不知归路
    2021-02-05 13:36

    It's happening very quickly, that's why you don't see anything. What you're doing:

    • ioctl: Is there data for me ? No, nothing yet
    • recv: Block until there is data for me. Some (short) time later: Here is your data

    So if you really want to see FIONREAD, just wait for it.

    /* Try FIONREAD until we get *something* or ioctl fails. */
    while (!bytesAv && ioctl (m_Socket,FIONREAD,&bytesAv) >= 0)
        sleep(1);
    

提交回复
热议问题