linux C语言 ioctl

linux C语言 ioctl,第1张

文章目录
    • man 2 文档

man 2 文档
IOCTL(2)                                                             Linux Programmer's Manual                                                            IOCTL(2)

NAME
       ioctl - control device

SYNOPSIS
       #include 

       int ioctl(int fd, unsigned long request, ...);

DESCRIPTION
       The  ioctl()  function  manipulates  the underlying device parameters of special files.  In particular, many operating characteristics of character special
       files (e.g., terminals) may be controlled with ioctl() requests.  The argument fd must be an open file descriptor.
       //ioctl() 函数 *** 作特殊文件的底层设备参数。 
       //特别是,字符特殊文件(例如终端)的许多 *** 作特性可以通过 ioctl() 请求进行控制。 
       //参数 fd 必须是打开的文件描述符。

       The second argument is a device-dependent request code.  The third argument is an untyped pointer to memory.  It's traditionally char *argp (from the  days
       before void * was valid C), and will be so named for this discussion.
       //第二个参数是设备相关的请求代码。 
       //第三个参数是指向内存的无类型指针。 
       //传统上它是 char *argp (从 void * 是有效 C 之前的日子开始),并且将在本次讨论中如此命名。

       An  ioctl()  request  has  encoded  in it whether the argument is an in parameter or out parameter, and the size of the argument argp in bytes.  Macros and
       defines used in specifying an ioctl() request are located in the file <sys/ioctl.h>.
       //ioctl() 请求已在其中编码,无论参数是输入参数还是输出参数,以及参数 argp 的大小(以字节为单位)。 
       //用于指定 ioctl() 请求的宏和定义位于文件  中。

RETURN VALUE
       Usually, on success zero is returned.  A few ioctl() requests use the return value as an output parameter and return a nonnegative value  on  success.   On
       error, -1 is returned, and errno is set appropriately.
       //通常,成功时返回零。 
       //一些 ioctl() 请求使用返回值作为输出参数,并在成功时返回一个非负值。 
       //出错时,返回 -1,并适当设置 errno。

ERRORS
       EBADF  fd is not a valid descriptor.	
       			//fd 不是有效的描述符。

       EFAULT argp references an inaccessible memory area.
       			//argp 引用了一个不可访问的内存区域。

       EINVAL request or argp is not valid.
       			//请求或 argp 无效。

       ENOTTY fd is not associated with a character special device.
       			//fd 不与字符特殊设备相关联。

       ENOTTY The specified request does not apply to the kind of object that the descriptor fd references.
       			//指定的请求不适用于描述符 fd 引用的对象类型。


可以设置socket_fd状态阻塞或非阻塞,参考文章:KYSL socket卡住问题(connect()函数阻塞)解决方案:ioctl()设置socket_fd为非阻塞的,connect()之后用select()+getsockopt()判断

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/875264.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-13
下一篇 2022-05-13

发表评论

登录后才能评论

评论列表(0条)

保存