diff options
Diffstat (limited to 'libhw_generic/include')
-rw-r--r-- | libhw_generic/include/libhw/generic/io.h | 23 | ||||
-rw-r--r-- | libhw_generic/include/libhw/generic/net.h | 26 | ||||
-rw-r--r-- | libhw_generic/include/libhw/generic/spi.h | 1 |
3 files changed, 33 insertions, 17 deletions
diff --git a/libhw_generic/include/libhw/generic/io.h b/libhw_generic/include/libhw/generic/io.h index 681c5ef..9128bd3 100644 --- a/libhw_generic/include/libhw/generic/io.h +++ b/libhw_generic/include/libhw/generic/io.h @@ -9,6 +9,8 @@ #include <stddef.h> /* for size_t */ +#include <libobj/obj.h> + /* structs ********************************************************************/ #if __unix__ @@ -26,4 +28,25 @@ struct duplex_iovec { size_t iov_len; }; +/* basic interfaces ***********************************************************/ + +/** + * Return 0 on success, -errno on error. + */ +#define io_closer_LO_IFACE \ + LO_FUNC(int, close) +LO_INTERFACE(io_closer) +#define io_close(c) LO_CALL(c, close) + +/** + * All methods return 0 on success, -errno on error. + */ +#define io_bidi_closer_LO_IFACE \ + LO_NEST(io_closer) \ + LO_FUNC(int, close_read) \ + LO_FUNC(int, close_write) +LO_INTERFACE(io_bidi_closer) +#define io_close_read(c) LO_CALL(c, close_read) +#define io_close_write(c) LO_CALL(c, close_write) + #endif /* _LIBHW_GENERIC_IO_H_ */ diff --git a/libhw_generic/include/libhw/generic/net.h b/libhw_generic/include/libhw/generic/net.h index 0386e12..d70034e 100644 --- a/libhw_generic/include/libhw/generic/net.h +++ b/libhw_generic/include/libhw/generic/net.h @@ -13,7 +13,6 @@ #include <stdint.h> /* for uint{n}_t} */ #include <sys/types.h> /* for ssize_t */ -#include <libobj/obj.h> #include <libhw/generic/io.h> /* Errnos *********************************************************************/ @@ -69,13 +68,13 @@ lo_interface net_stream_conn; /** \ * The net_stream_conn returned from accept() may still be \ * valid after the listener is closed. \ - * \ - * Return 0 on success, -errno on error. \ */ \ - LO_FUNC(int, close) + LO_NEST(io_closer) LO_INTERFACE(net_stream_listener) #define net_stream_conn_LO_IFACE \ + LO_NEST(io_bidi_closer) \ + \ /** \ * Return bytes-read on success, 0 on EOF, -errno on error; a \ * short read is *not* an error. \ @@ -103,12 +102,7 @@ LO_INTERFACE(net_stream_listener) * expensive to implement), so if you have concurrent writers then you \ * should arrange for a mutex to protect the connection. \ */ \ - LO_FUNC(ssize_t, write, void *buf, size_t count) \ - \ - /** \ - * Return 0 on success, -errno on error. \ - */ \ - LO_FUNC(int, close, bool rd, bool wr) + LO_FUNC(ssize_t, write, void *buf, size_t count) LO_INTERFACE(net_stream_conn) /* Packets (e.g. UDP) *********************************************************/ @@ -117,7 +111,7 @@ LO_INTERFACE(net_stream_conn) LO_FUNC(ssize_t, sendto, \ void *buf, size_t len, \ struct net_ip4_addr node, uint16_t port) \ - \ + \ /** \ * @return The full length of the message, which may be more \ * than the given `len` (as if the Linux MSG_TRUNC flag were \ @@ -126,11 +120,11 @@ LO_INTERFACE(net_stream_conn) LO_FUNC(ssize_t, recvfrom, \ void *buf, size_t len, \ struct net_ip4_addr *ret_node, uint16_t *ret_port) \ - \ - LO_FUNC(void, set_read_deadline, \ + \ + LO_FUNC(void, set_recv_deadline, \ uint64_t ns_since_boot) \ - \ - LO_FUNC(int, close) + \ + LO_NEST(io_closer) LO_INTERFACE(net_packet_conn) /* Interfaces *****************************************************************/ @@ -145,7 +139,7 @@ struct net_iface_config { LO_FUNC(struct net_eth_addr , hwaddr ) \ LO_FUNC(void , ifup , struct net_iface_config) \ LO_FUNC(void , ifdown ) \ - \ + \ LO_FUNC(lo_interface net_stream_listener, tcp_listen, uint16_t local_port) \ LO_FUNC(lo_interface net_stream_conn , tcp_dial , struct net_ip4_addr remote_node, uint16_t remote_port) \ LO_FUNC(lo_interface net_packet_conn , udp_conn , uint16_t local_port) diff --git a/libhw_generic/include/libhw/generic/spi.h b/libhw_generic/include/libhw/generic/spi.h index c97232a..a4b0b22 100644 --- a/libhw_generic/include/libhw/generic/spi.h +++ b/libhw_generic/include/libhw/generic/spi.h @@ -9,7 +9,6 @@ #include <stddef.h> /* for size_t */ -#include <libobj/obj.h> #include <libhw/generic/io.h> enum spi_mode { |