1
0
mirror of https://github.com/libssh2/libssh2.git synced 2026-10-24 03:48:58 +03:00
Files
libssh2/docs/libssh2_session_set_read_timeout.md
Viktor Szakats 9c421761bc src: use abstract internal time type, bump resolution to milliseconds
To honor the actual millisecond timeout set via
`libssh2_session_set_timeout()`, to open the possibility for the same in
other APIs, and to use monotonic time if available.

- add internal abstract time types and macros for handling point in time
  and time intervals, and use them throughout the codebase.
- bump internal abstract time resolution to milliseconds (from seconds).
  Use signed 64-bit integers.
- replace existing millisecond-resolution code in `libssh2_poll()` with
  the internal abstract time interface.
- bump 'now' function to retrieve millisecond-resolution monotonic time
  from the system, if available.

Also:
- append `_s` or `_ms` to public API arguments to tell the time unit.
- keepalive: minor tidy-ups.
- make `ssh2_now()` return at least 1 in the fallback,
  `time(NULL)`-based codepath to not confuse a zero value with unset
  time.
  Credits: Stefan Eissing
  Ref: 5649b21297
  Ref: https://github.com/curl/curl/pull/21034
- this leaves existing `ssh2_gettimeofday()` (together with its
  Windows-specific local implementation) with a single caller,
  `ssh2_deb_low()`.

Refs:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_gettime.html
https://www.man7.org/linux/man-pages/man3/clock_gettime.3.html
https://pubs.opengroup.org/onlinepubs/009604599/functions/gettimeofday.html
https://www.man7.org/linux/man-pages/man2/gettimeofday.2.html
https://learn.microsoft.com/windows/win32/api/profileapi/nf-profileapi-queryperformancefrequency
https://learn.microsoft.com/windows/win32/api/profileapi/nf-profileapi-queryperformancecounter
https://stackoverflow.com/questions/5404277/porting-clock-gettime-to-windows

Reported-and-patch-proposal-by: Trzik on github
Based-on-patch-proposals-by: Ryan Kelley
Fixes #1497
Ref: #1818
Closes #1893
Follow-up to 772abc7a85 #1919

Closes #2341
2026-07-19 02:56:04 +02:00

789 B

c, SPDX-License-Identifier, Title, Section, Source, See-also
c SPDX-License-Identifier Title Section Source See-also
Copyright (C) The libssh2 project and its contributors. BSD-3-Clause libssh2_session_set_read_timeout 3 libssh2
libssh2_session_get_read_timeout(3)

NAME

libssh2_session_set_read_timeout - set timeout for packet read functions

SYNOPSIS

#include <libssh2.h>

void libssh2_session_set_read_timeout(LIBSSH2_SESSION *session,
                                      long timeout_s);

DESCRIPTION

Set the timeout_s in seconds for how long libssh2 packet read function calls may wait until they consider the situation an error and return LIBSSH2_ERROR_TIMEOUT.

By default or if you set the timeout to zero, the timeout is set to 60 seconds.

RETURN VALUE

Nothing

AVAILABILITY

Added in 1.10.1