diff options
Diffstat (limited to 'libmisc')
-rw-r--r-- | libmisc/include/libmisc/net.h | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/libmisc/include/libmisc/net.h b/libmisc/include/libmisc/net.h index 43c4a48..057e875 100644 --- a/libmisc/include/libmisc/net.h +++ b/libmisc/include/libmisc/net.h @@ -33,15 +33,23 @@ struct net_eth_addr { /* Streams (e.g. TCP) *********************************************************/ -struct net_stream_listener; -struct net_stream_conn; +struct net_stream_listener_vtable; +struct net_stream_conn_btable; + +typedef struct { + struct net_stream_listener_vtable *vtable; +} implements_net_stream_listener; + +typedef struct { + struct net_stream_conn_vtable *vtable; +} implements_net_stream_conn; struct net_stream_listener_vtable { /** * It is invalid to accept() a new connection if an existing * connection is still open. */ - struct net_stream_conn *(*accept)(struct net_stream_listener *self); + implements_net_stream_conn *(*accept)(implements_net_stream_listener *self); }; struct net_stream_conn_vtable { @@ -49,7 +57,8 @@ struct net_stream_conn_vtable { * Return bytes-read on success, 0 on EOF, -errno on error; a * short read is *not* an error. */ - ssize_t (*read)(struct net_stream_conn *self, void *buf, size_t count); + ssize_t (*read)(implements_net_stream_conn *self, + void *buf, size_t count); /** * Return `count` on success, -errno on error; a short write *is* an @@ -59,36 +68,32 @@ struct net_stream_conn_vtable { * expensive to implement), so if you have concurrent writers then you * should arrange for a mutex to protect the connection. */ - ssize_t (*write)(struct net_stream_conn *self, void *buf, size_t count); + ssize_t (*write)(implements_net_stream_conn *self, + void *buf, size_t count); /** * Return 0 on success, -errno on error. */ - int (*close)(struct net_stream_conn *self, bool rd, bool wr); + int (*close)(implements_net_stream_conn *self, + bool rd, bool wr); }; -typedef struct net_stream_listener { - struct net_stream_listener_vtable *vtable; -} implements_net_stream_listener; - -typedef struct net_stream_conn { - struct net_stream_conn_vtable *vtable; -} implements_net_stream_conn; - /* Packets (e.g. UDP) *********************************************************/ -struct net_packet_conn; +struct net_packet_conn_vtable; + +typedef struct { + struct net_packet_conn_vtable *vtable; +} implements_net_packet_conn; struct net_packet_conn_vtable { - ssize_t (*sendto )(struct net_packet_conn *self, void *buf, size_t len, + ssize_t (*sendto )(implements_net_packet_conn *self, + void *buf, size_t len, struct net_ip4_addr node, uint16_t port); - ssize_t (*recvfrom)(struct net_packet_conn *self, void *buf, size_t len, + ssize_t (*recvfrom)(implements_net_packet_conn *self, + void *buf, size_t len, struct net_ip4_addr *ret_node, uint16_t *ret_port); - int (*close )(struct net_packet_conn *self); + int (*close )(implements_net_packet_conn *self); }; -typedef struct net_packet_conn { - struct net_packet_conn_vtable *vtable; -} implements_net_packet_conn; - #endif /* _LIBMISC_NET_H_ */ |