RTE OSAdapter POSIX
0.1.0 build 41b3eb3
POSIX/Linux OAL OSAdapter for Platform_RTE
Toggle main menu visibility
Loading...
Searching...
No Matches
rte_posix_osadapter_sockbuf.c
Go to the documentation of this file.
1
/* _POSIX_C_SOURCE: the same feature-test macro as every other file of this product (it builds strict C99); glibc
2
* declares socklen_t, setsockopt() and getsockopt() in <sys/socket.h> under it as well. */
3
#define _POSIX_C_SOURCE 200809L
4
11
#include "
rte_posix_osadapter_sockbuf.h
"
12
13
#include <limits.h>
14
#include <stdbool.h>
15
#include <stdint.h>
16
#include <sys/socket.h>
17
18
#include "
rte_posix_osadapter_report.h
"
19
21
#if defined(__linux__)
23
#define POSIX_SOCKBUF_READBACK_FACTOR 2
24
#else
26
#define POSIX_SOCKBUF_READBACK_FACTOR 1
27
#endif
28
30
32
static
rte_status_t
apply_one
(
int
fd,
int
option, uint32_t bytes,
bool
*capped);
33
35
37
39
42
static
rte_status_t
apply_one
(
int
fd,
int
option, uint32_t bytes,
bool
*capped)
43
{
44
rte_status_t status = RTE_STATUS_OK;
45
46
if
(bytes != 0U)
47
{
48
const
int
requested = (bytes > (uint32_t)INT_MAX) ? INT_MAX : (int)bytes;
49
int
confirmed = 0;
50
socklen_t length = (socklen_t)
sizeof
(confirmed);
51
52
status = RTE_STATUS_INTERNAL_ERROR;
53
if
(setsockopt(fd, SOL_SOCKET, option, &requested, (socklen_t)
sizeof
(requested)) == 0)
54
{
55
if
(getsockopt(fd, SOL_SOCKET, option, &confirmed, &length) == 0)
56
{
57
if
(length == (socklen_t)
sizeof
(confirmed))
58
{
59
const
int64_t expected = (int64_t)requested * (int64_t)
POSIX_SOCKBUF_READBACK_FACTOR
;
60
61
if
((int64_t)confirmed < expected)
62
{
63
*capped =
true
;
64
}
65
status = RTE_STATUS_OK;
66
}
67
}
68
}
69
}
70
return
status;
71
}
72
74
75
rte_status_t
posix_socket_apply_buffers
(
int
fd,
const
rte_netlink_config_t *config)
76
{
77
rte_status_t status = RTE_STATUS_INVALID_PARAM;
78
bool
capped =
false
;
79
80
if
(config != NULL)
81
{
82
status =
apply_one
(fd, SO_RCVBUF, config->rcvbuf_bytes, &capped);
83
if
(status == RTE_STATUS_OK)
84
{
85
status =
apply_one
(fd, SO_SNDBUF, config->sndbuf_bytes, &capped);
86
}
87
if
((status == RTE_STATUS_OK) && capped)
88
{
89
/* OSA rules R5/R6: the OS kept a smaller buffer than configured (Linux caps at net.core.rmem_max /
90
* wmem_max without an error). Reported once per socket; the link is kept (REQ-OAL-NETLINK-015). */
91
POSIX_OSA_REPORT_RT_ATTRIBUTE(
"socket buffer size capped"
);
92
}
93
}
94
return
status;
95
}
rte_posix_osadapter_report.h
Private helper: reports a real-time attribute this OSAdapter could not apply (OSA rules R1/R2/R6).
posix_socket_apply_buffers
rte_status_t posix_socket_apply_buffers(int fd, const rte_netlink_config_t *config)
Sets and confirms config->rcvbuf_bytes (SO_RCVBUF) and config->sndbuf_bytes (SO_SNDBUF) on a socket.
Definition
rte_posix_osadapter_sockbuf.c:75
apply_one
static rte_status_t apply_one(int fd, int option, uint32_t bytes, bool *capped)
Definition
rte_posix_osadapter_sockbuf.c:42
POSIX_SOCKBUF_READBACK_FACTOR
#define POSIX_SOCKBUF_READBACK_FACTOR
Definition
rte_posix_osadapter_sockbuf.c:26
rte_posix_osadapter_sockbuf.h
Private helper: applies the socket buffer sizes of a link config (OSA rules R5, R6).
src
rte_posix_osadapter_sockbuf.c
Generated by
1.18.0