本文介绍了从Unix移植ioctl()调用到Linux,FIONBIO错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用ioctl()获取准备读取的字节数

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

我这样做的方式是:

mysocket=socket(....);
ioctl(mysocket, FIONBIO, &zero);
connect(.....);
ioctl( mysocket, FIONREAD, &numBytes );
read(mysocket, buffer, numBytes);

这在Unix上工作正常,现在我必须将其移植到linux我不断收到错误消息

this was working fine in unix, now i have to port it to linuxi keep getting ERROR

是否有一些特定于Linux的头文件?还是'FIOBIO'在Linux中根本不起作用?

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

我包括以下标题:

#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>

我被删除

#include <sys/filio.h>

因为它抛出错误,提示未找到sys/filio.h

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

推荐答案

您是否尝试过包含 sys/ioctl.h ?

此代码对我有用:

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

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

当我执行grep -R FIONBIO /usr/include时,可以在这里找到它:

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

/usr/include/asm-generic/ioctls.h:#define FIONBIO 0x5421

这篇关于从Unix移植ioctl()调用到Linux,FIONBIO错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 07:22