将 ioctl() 调用从 unix 移植到 linux,FIONBIO 出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9609781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
porting ioctl() calls from unix to linux, error with FIONBIO
提问by maheshg
i want to use ioctl() to get the number of bytes ready to be read
我想使用 ioctl() 来获取准备读取的字节数
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
这在 unix 中运行良好,现在我必须将它移植到 linux 我不断收到错误
error: 'FIONBIO' was not declared in this scope
错误:“FIONBIO”未在此范围内声明
Is there some header file specific for linux? or 'FIOBIO' doesnt work at all in linux?
是否有一些特定于 linux 的头文件?或“FIOBIO”在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
因为它抛出错误说找不到 sys/filio.h
采纳答案by mfontanini
Have you tried including sys/ioctl.h?
你试过包括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:
当我执行时grep -R FIONBIO /usr/include
,它在这里找到:
/usr/include/asm-generic/ioctls.h:#define FIONBIO 0x5421