xref: /libuv/docs/src/fs_poll.rst (revision c4bd9f48)
1
2.. _fs_poll:
3
4:c:type:`uv_fs_poll_t` --- FS Poll handle
5=========================================
6
7FS Poll handles allow the user to monitor a given path for changes. Unlike
8:c:type:`uv_fs_event_t`, fs poll handles use `stat` to detect when a file has
9changed so they can work on file systems where fs event handles can't.
10
11
12Data types
13----------
14
15.. c:type:: uv_fs_poll_t
16
17    FS Poll handle type.
18
19.. c:type:: void (*uv_fs_poll_cb)(uv_fs_poll_t* handle, int status, const uv_stat_t* prev, const uv_stat_t* curr)
20
21    Callback passed to :c:func:`uv_fs_poll_start` which will be called repeatedly
22    after the handle is started, when any change happens to the monitored path.
23
24    The callback is invoked with `status < 0` if `path` does not exist
25    or is inaccessible. The watcher is *not* stopped but your callback is
26    not called again until something changes (e.g. when the file is created
27    or the error reason changes).
28
29    When `status == 0`, the callback receives pointers to the old and new
30    :c:type:`uv_stat_t` structs. They are valid for the duration of the
31    callback only.
32
33
34Public members
35^^^^^^^^^^^^^^
36
37N/A
38
39.. seealso:: The :c:type:`uv_handle_t` members also apply.
40
41
42API
43---
44
45.. c:function:: int uv_fs_poll_init(uv_loop_t* loop, uv_fs_poll_t* handle)
46
47    Initialize the handle.
48
49.. c:function:: int uv_fs_poll_start(uv_fs_poll_t* handle, uv_fs_poll_cb poll_cb, const char* path, unsigned int interval)
50
51    Check the file at `path` for changes every `interval` milliseconds.
52
53    .. note::
54        For maximum portability, use multi-second intervals. Sub-second intervals will not detect
55        all changes on many file systems.
56
57.. c:function:: int uv_fs_poll_stop(uv_fs_poll_t* handle)
58
59    Stop the handle, the callback will no longer be called.
60
61.. c:function:: int uv_fs_poll_getpath(uv_fs_poll_t* handle, char* buffer, size_t* size)
62
63    Get the path being monitored by the handle. The buffer must be preallocated
64    by the user. Returns 0 on success or an error code < 0 in case of failure.
65    On success, `buffer` will contain the path and `size` its length. If the buffer
66    is not big enough `UV_ENOBUFS` will be returned and `size` will be set to
67    the required size.
68
69    .. versionchanged:: 1.3.0 the returned length no longer includes the terminating null byte,
70                        and the buffer is not null terminated.
71
72    .. versionchanged:: 1.9.0 the returned length includes the terminating null
73                        byte on `UV_ENOBUFS`, and the buffer is null terminated
74                        on success.
75
76
77.. seealso:: The :c:type:`uv_handle_t` API functions also apply.
78