readcond()函数帮助文档

来源QNX帮助文档。 

Read data from a terminal device

Synopsis:
#include <unistd.h>

int readcond( int fd,
              void * buf,
              int n,
              int min,
              int time,
              int timeout );Arguments:
fd 
The file descriptor associated with the terminal device that you want to read from. 
buf 
A pointer to a buffer into which readcond() can put the data. 
n 
The maximum number of bytes to read. 
min, time, timeout 
When used in RAW mode, these arguments override the behavior of the MIN and TIME members of the terminal's termios structure.

 MIN:参数是最小到达的字节数;

TIME:字节流暂停

TIMEOUT:时间

In the case where multiple conditions are specified, the read will be satisfied when any one of them is satisfied. 

MIN
The qualifier MIN is useful when an application has knowledge of the number of characters it expects to receive. 

Any protocol that knows the character count for a frame of data can use MIN to wait for the entire frame to arrive. This significantly reduces IPC and process scheduling. MIN is often used in conjunction with TIME or TIMEOUT. MIN is part of the POSIX standard. 

TIME
The qualifier TIME is useful when an application is receiving streaming data and wishes to be notified when the data stops or pauses. The pause time is specified in 1/10 of a second. TIME is part of the POSIX standard. 

TIMEOUT
The qualifier TIMEOUT is useful when an application has knowledge of how long it should wait for data before timing out. The timeout is specified in 1/10 of a second. 

Any protocol that knows the character count for a frame of data it expects to receive can use TIMEOUT. This in combination with the baud rate allows a reasonable guess to be made when data should be available. It acts as a deadman timer to detect dropped characters. It can also be used in interactive programs with user input to timeout a read if no response is available within a given time. 

TIMEOUT is a QNX extension and isn't part of the POSIX standard. 

FORWARD
The qualifier FORWARD is useful when a protocol is delimited by a special framing character. For example, the PPP protocol used for TCP/IP over a serial link start and end its packets with a framing character. When used in conjunction with TIMEOUT, the FORWARD character can greatly improve the efficiency of a protocol implementation. The protocol process will receive complete frames, rather than character by character. In the case of a dropped framing character, TIMEOUT or TIME can be used to quickly recover. 

This greatly minimizes the amount of IPC work for the OS and results in a much lower processor utilization for a given TCP/IP data rate. It is interesting to note that PPP doesn't contain a character count for its frames. Without the data-forwarding character, an implementation would be forced to read the data one character at a time. 

FORWARD is a QNX extension and isn't part of the POSIX standard. 

The (M, 0, t) case is useful for communications protocols that cannot afford to block forever waiting for data that may never arrive.

例如: readcond(fd ,buf,n,1,0,1); //读到至少一个字节或者阻塞1秒钟。

ps:这个跟select函数的功能很像。

The (M, T, t) case is provided to permit readcond() to return when a burst of data ends (as in the (M, T, 0) case), but also to return if no burst at all is detected within a reasonable amount of time.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值