diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:54:46 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:54:46 +0000 |
commit | cd7b005519ade8ab6c97fcb21590b71b7d1be6e3 (patch) | |
tree | c611a8d0cd5e8f68f41b8c2d16ba580e0f40a38d /rtrlib/transport/transport.c | |
parent | Initial commit. (diff) | |
download | librtr-41bce423b47dc1839a0d83b8627edb74c06b8b6e.tar.xz librtr-41bce423b47dc1839a0d83b8627edb74c06b8b6e.zip |
Adding upstream version 0.8.0.upstream/0.8.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'rtrlib/transport/transport.c')
-rw-r--r-- | rtrlib/transport/transport.c | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/rtrlib/transport/transport.c b/rtrlib/transport/transport.c new file mode 100644 index 0000000..d1bdfc5 --- /dev/null +++ b/rtrlib/transport/transport.c @@ -0,0 +1,87 @@ +/* + * This file is part of RTRlib. + * + * This file is subject to the terms and conditions of the MIT license. + * See the file LICENSE in the top level directory for more details. + * + * Website: http://rtrlib.realmv6.org/ + */ + +#include "transport_private.h" + +#include "rtrlib/lib/utils_private.h" + +inline int tr_open(struct tr_socket *socket) +{ + return socket->open_fp(socket->socket); +} + +inline void tr_close(struct tr_socket *socket) +{ + socket->close_fp(socket->socket); +} + +inline void tr_free(struct tr_socket *socket) +{ + socket->free_fp(socket); +} + +inline int tr_send(const struct tr_socket *socket, const void *pdu, const size_t len, const time_t timeout) +{ + return socket->send_fp(socket->socket, pdu, len, timeout); +} + +inline int tr_recv(const struct tr_socket *socket, void *buf, const size_t len, const time_t timeout) +{ + return socket->recv_fp(socket->socket, buf, len, timeout); +} + +/* cppcheck-suppress unusedFunction */ +inline const char *tr_ident(struct tr_socket *sock) +{ + return sock->ident_fp(sock->socket); +} + +int tr_send_all(const struct tr_socket *socket, const void *pdu, const size_t len, const time_t timeout) +{ + unsigned int total_send = 0; + time_t end_time; + + lrtr_get_monotonic_time(&end_time); + end_time = end_time + timeout; + + while (total_send < len) { + time_t cur_time; + int rtval; + + lrtr_get_monotonic_time(&cur_time); + + rtval = tr_send(socket, ((char *)pdu) + total_send, (len - total_send), (end_time - cur_time)); + if (rtval < 0) + return rtval; + total_send += rtval; + } + return total_send; +} + +int tr_recv_all(const struct tr_socket *socket, const void *pdu, const size_t len, const time_t timeout) +{ + size_t total_recv = 0; + time_t end_time; + + lrtr_get_monotonic_time(&end_time); + end_time += timeout; + + while (total_recv < len) { + time_t cur_time; + int rtval; + + lrtr_get_monotonic_time(&cur_time); + + rtval = tr_recv(socket, ((char *)pdu) + total_recv, (len - total_recv), end_time - cur_time); + if (rtval < 0) + return rtval; + total_recv += rtval; + } + return total_recv; +} |