diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-28 23:51:15 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-28 23:51:15 -0600 |
commit | 4d185da010aea1d307c8ff7807ef3d4359083ed0 (patch) | |
tree | 0eef6621e8cadfb827e35cc0f426fdebb6096d10 /libhw/common_include | |
parent | 52d48b9ea39a990295fdaf53dea492637051bd10 (diff) |
wip host net timeout
Diffstat (limited to 'libhw/common_include')
-rw-r--r-- | libhw/common_include/libhw/generic/bootclock.h | 22 | ||||
-rw-r--r-- | libhw/common_include/libhw/generic/net.h | 16 |
2 files changed, 38 insertions, 0 deletions
diff --git a/libhw/common_include/libhw/generic/bootclock.h b/libhw/common_include/libhw/generic/bootclock.h new file mode 100644 index 0000000..bea5338 --- /dev/null +++ b/libhw/common_include/libhw/generic/bootclock.h @@ -0,0 +1,22 @@ +/* libhw/generic/bootclock.h - Device-independent clock definitions + * + * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#ifndef _LIBHW_GENERIC_BOOTCLOCK_H_ +#define _LIBHW_GENERIC_BOOTCLOCK_H_ + +#include <stdint.h> /* for uint{n}_t and UINT{n}_C */ + +#define NS_PER_S UINT64_C(1000000000) /* needs at least log₂(10⁹) ≈ 29.9 bits */ +#define US_PER_S UINT64_C(1000000) /* needs at least log₂(10⁶) ≈ 19.9 bits */ +#define MS_PER_S UINT64_C(1000) /* needs at least log₂(10³) ≈ 9.9 bits */ + +/** + * (2⁶⁴-1 nanoseconds is more than 500 years; there is little + * risk of this overflowing) + */ +uint64_t bootclock_get_ns(void); + +#endif /* _LIBHW_GENERIC_BOOTCLOCK_H_ */ diff --git a/libhw/common_include/libhw/generic/net.h b/libhw/common_include/libhw/generic/net.h index 419a8f2..af8844f 100644 --- a/libhw/common_include/libhw/generic/net.h +++ b/libhw/common_include/libhw/generic/net.h @@ -61,6 +61,20 @@ struct net_stream_conn_vtable { void *buf, size_t count); /** + * Set a timestamp after which calls to read() will return + * NET_ETIMEDOUT. The timestamp is in nanoseconds on the + * system monotonic clock, which is usually (on pico-sdk and + * on the Linux kernel) nanoseconds-since-boot. + * + * A zero value disables the deadline. + * + * (2⁶⁴-1 nanoseconds is more than 500 years; there is little + * risk of this overflowing) + */ + void (*set_read_deadline)(implements_net_stream_conn *self, + uint64_t ns_since_boot); + + /** * Return `count` on success, -errno on error; a short write *is* an * error. * @@ -93,6 +107,8 @@ struct net_packet_conn_vtable { ssize_t (*recvfrom)(implements_net_packet_conn *self, void *buf, size_t len, struct net_ip4_addr *ret_node, uint16_t *ret_port); + void (*set_read_deadline)(implements_net_packet_conn *self, + uint64_t ns_since_boot); int (*close )(implements_net_packet_conn *self); }; |