diff --git a/src/fdwatcher.c b/src/fdwatcher.c index 711628d..5a120b1 100644 --- a/src/fdwatcher.c +++ b/src/fdwatcher.c @@ -129,8 +129,9 @@ fdwatcher_wait(FdWatcher *fdw, void **events, int nevents, int timeout) struct timespec *tsp = NULL; if (timeout != -1) { - ts.tv_sec = timeout; - ts.tv_nsec = 0; + // timeout is milleseconds, convert to timespec + ts.tv_sec = timeout / 1000; + ts.tv_nsec = timeout % 1000 * 1000 * 1000; tsp = &ts; } diff --git a/src/fdwatcher.h b/src/fdwatcher.h index 046465b..5233628 100644 --- a/src/fdwatcher.h +++ b/src/fdwatcher.h @@ -113,8 +113,8 @@ int fdwatcher_remove(FdWatcher *fdw, int fd); /* * Wait for events and return when one or more are seen. `events` and * `nevents` are an array of pointers (type agnostic) and the number of - * pointers in the array to fill. `timeout` is an optional timeout to wait for - * events, set to -1 to wait indefinitely. + * pointers in the array to fill. `timeout` is an optional timeout (in + * milliseconds) to wait for events, set to -1 to wait indefinitely. * * This function will return the number of events that were seen. For each * event that was seen, its user data pointer (set in `fdwatcher_add`) will be