poll_fd

poll_fd(fd, timeout_s::Real; readable=false, writable=false)

Monitor a file descriptor fd for changes in the read or write availability, and with a timeout given by timeout_s seconds.

The keyword arguments determine which of read and/or write status should be monitored; at least one of them must be set to true.

The returned value is an object with boolean fields readable, writable, and timedout, giving the result of the polling.

Examples

  1. Monitor a file descriptor for readability:

    julia> result = poll_fd(fd, 1.0, readable=true)
    julia> result.readable
    true
    julia> result.writable
    false
    julia> result.timedout
    false

    This example monitors the file descriptor fd for changes in readability. The function will wait for a maximum of 1 second (timeout_s) for the file descriptor to become readable. The result object indicates that the file descriptor is readable, not writable, and the polling did not time out.

  2. Monitor a file descriptor for writability:

    julia> result = poll_fd(fd, 0.5, writable=true)
    julia> result.readable
    false
    julia> result.writable
    true
    julia> result.timedout
    false

    In this example, the function monitors the file descriptor fd for changes in writability. The timeout is set to 0.5 seconds. The result object indicates that the file descriptor is not readable but is writable, and the polling did not time out.

  3. Monitor a file descriptor for both readability and writability:
    julia> result = poll_fd(fd, 2.0, readable=true, writable=true)
    julia> result.readable
    true
    julia> result.writable
    true
    julia> result.timedout
    false

    This example monitors the file descriptor fd for changes in both readability and writability. The timeout is set to 2.0 seconds. The result object indicates that the file descriptor is both readable and writable, and the polling did not time out.

Common mistake example:

julia> result = poll_fd(fd, 0.1, readable=false, writable=false)
ERROR: ArgumentError: At least one of `readable` and `writable` must be set to true.

Here, the function call is incorrect because both readable and writable arguments are set to false. At least one of them must be set to true to monitor the file descriptor for changes.

See Also

abspath, basename, chmod, countlines, cp, ctime, dirname, download, evalfile, expanduser, fdio, filemode, filesize, functionloc, gperm, homedir, include_string, isabspath, isblockdev, ischardev, isdir, isdirpath, isexecutable, isfifo, isfile, islink, ismount, ispath, isreadable, issetgid, issetuid, issticky, iswritable, joinpath, less, lstat, mkdir, mkpath, mktemp, mktempdir, mtime, mv, normpath, operm, poll_fd, poll_file, readall, readcsv, readdir, readdlm, readlines, readlink, realpath, relpath, rm, splitdir, splitdrive, splitext, stat, symlink, tempdir, tempname, touch, truncate, uperm, watch_file, writecsv,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: