net: sockets: Remove socket offloading interface
Instead of using a custom offloading interface, users can use `NET_SOCKET_REGISTER` macro to register custom socket API provider. This solution removes a limitation, that only one offloaded interface can be registered and that it cannot be used together with native IP stack. The only exception remainig are DNS releated operations - `getaddrinfo`/`freeaddrinfo`, which, when offloaded, have to be registered specifically. Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
parent
561973060e
commit
bea1093e62
8 changed files with 80 additions and 289 deletions
|
@ -8,29 +8,34 @@
|
|||
LOG_MODULE_REGISTER(net_socket_offload, CONFIG_NET_SOCKETS_LOG_LEVEL);
|
||||
|
||||
#include <net/socket_offload.h>
|
||||
#include <net/socket.h>
|
||||
|
||||
/* Only one provider may register socket operations upon boot. */
|
||||
const struct socket_offload *socket_ops;
|
||||
#include "sockets_internal.h"
|
||||
|
||||
void socket_offload_register(const struct socket_offload *ops)
|
||||
const struct socket_dns_offload *dns_offload;
|
||||
|
||||
void socket_offload_dns_register(const struct socket_dns_offload *ops)
|
||||
{
|
||||
__ASSERT_NO_MSG(ops);
|
||||
__ASSERT_NO_MSG(socket_ops == NULL);
|
||||
__ASSERT_NO_MSG(dns_offload == NULL);
|
||||
|
||||
socket_ops = ops;
|
||||
dns_offload = ops;
|
||||
}
|
||||
|
||||
int fcntl(int fd, int cmd, ...)
|
||||
int socket_offload_getaddrinfo(const char *node, const char *service,
|
||||
const struct zsock_addrinfo *hints,
|
||||
struct zsock_addrinfo **res)
|
||||
{
|
||||
__ASSERT_NO_MSG(socket_ops);
|
||||
__ASSERT_NO_MSG(socket_ops->fcntl);
|
||||
__ASSERT_NO_MSG(dns_offload);
|
||||
__ASSERT_NO_MSG(dns_offload->getaddrinfo);
|
||||
|
||||
va_list args;
|
||||
int res;
|
||||
|
||||
va_start(args, cmd);
|
||||
res = socket_ops->fcntl(fd, cmd, args);
|
||||
va_end(args);
|
||||
|
||||
return res;
|
||||
return dns_offload->getaddrinfo(node, service, hints, res);
|
||||
}
|
||||
|
||||
void socket_offload_freeaddrinfo(struct zsock_addrinfo *res)
|
||||
{
|
||||
__ASSERT_NO_MSG(dns_offload);
|
||||
__ASSERT_NO_MSG(dns_offload->freeaddrinfo);
|
||||
|
||||
return dns_offload->freeaddrinfo(res);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue