1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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;
}
|