RT-Thread API参考手册  3.1.1
嵌入式实时操作系统
文件描述符

文件描述符接口 更多...

函数

int fd_new (void)
 分配文件描述符 更多...
 
struct dfs_fd * fd_get (int fd)
 获取文件描述结构 更多...
 
void fd_put (struct dfs_fd *fd)
 放置文件描述符 更多...
 
int fd_is_open (const char *pathname)
 判断文件是否已被打开 更多...
 
int select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
 监视I/O设备状态 更多...
 

详细描述

文件描述符接口

函数说明

int fd_new ( void  )

分配文件描述符

返回
成功则返回新分配文件描述符,失败则返回 -1。
struct dfs_fd* fd_get ( int  fd)

获取文件描述结构

该函数将根据文件描述符返回文件描述符结构。

返回
成功返回文件描述符结构指针;失败则返回NULL
void fd_put ( struct dfs_fd *  fd)

放置文件描述符

参数
fd文件描述符结构指针
int fd_is_open ( const char *  pathname)

判断文件是否已被打开

参数
pathname文件路径名
返回
0 成功打开, -1 打开失败
int select ( int  nfds,
fd_set readfds,
fd_set writefds,
fd_set exceptfds,
struct timeval *  timeout 
)

监视I/O设备状态

该函数接口可以阻塞地同时探测一组支持非阻塞的I/O设备是否有事件发生(如可读,可写,有高优先级 的错误输出,出现错误等等),直至某一个设备触发了事件或者超过了指定的等待时间。

参数
nfds集合中所有文件描述符的范围,即所有文件描述符的最大值加1
readfds需要监视读变化的文件描述符集合
writefds需要监视写变化的文件描述符集合
exceptfds需要监视出现异常的文件描述符集合
timeoutselect的超时时间
返回
正值 监视的文件集合出现可读写事件或出错; 0 等待超时,没有可读写或错误的文件; 负值 select出现错误。
示例:
tcpclient_select_sample.c.