当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ - porting ioctl() calls from unix to linux, error with FIONBIO

问题描述:

i want to use ioctl() to get the number of bytes ready to be read

the way I did it is:

mysocket=socket(....);

ioctl(mysocket, FIONBIO, &zero);

connect(.....);

ioctl( mysocket, FIONREAD, &numBytes );

read(mysocket, buffer, numBytes);

this was working fine in unix, now i have to port it to linux

i keep getting ERROR

error: 'FIONBIO' was not declared in this scope

Is there some header file specific for linux? or 'FIOBIO' doesnt work at all in linux?

I have following headers included:

#include <cstring>

#include <sys/socket.h>

#include <stropts.h>

#include <fcntl.h>

#include <stddef.h>

#include <sys/un.h>

#include <sys/types.h>

#include <stdlib.h>

#include <sys/ioctl.h>

#include <netinet/in.h>

#include <arpa/inet.h>

#include <unistd.h>

#include <sys/select.h>

#include <fstream>

and i removed

#include <sys/filio.h>

since it was throwing errors saying sys/filio.h not found

网友答案:

Have you tried including sys/ioctl.h?

This code works for me:

#include <sys/ioctl.h>
#include <stdio.h>

int main() {
    printf("FIONBIO value %d\n", FIONBIO);
}

When I execute grep -R FIONBIO /usr/include, it's found here:

/usr/include/asm-generic/ioctls.h:#define FIONBIO 0x5421
分享给朋友:
您可能感兴趣的文章:
随机阅读: