Extracted from Pike v7.8 release 866 at 2016-11-06.
pike.ida.liu.se
[Top]
Stdio
Stdio.File

Method Stdio.File()->peek()


Method peek

int(-1..1) peek()
int(-1..1) peek(int|float timeout)
int(-1..1) peek(int|float timeout, int not_eof)

Description

Check if there is data available to read, or wait some time for available data to read.

More specifically, a later call to read() will return immediately, either due to data being present, or due to some error (eg if a socket has been closed).

Parameter timeout

Timeout in seconds.

Parameter not_eof

Flag for specifying handling of end of file. The following values are currently defined:

0

Traditional (and default) behaviour. Return 1 at EOF.

1

Regard EOF as an error. Return -1 and set errno() to return EPIPE at EOF.


Returns
1

There is data available to read() , or not_eof is 0 (zero) and we're at EOF. A later call to read() will not block.

0

There is no data available (ie timeout).

-1

Error condition. The error code returned by errno() has been updated.


See also

errno() , read()

Note

The function may be interrupted prematurely of the timeout (due to signals); check the timing manually if this is imporant.

Note

The not_eof parameter was added in Pike 7.7.

Note

This function was not available on NT in Pike 7.6 and earlier.