Skip to content

Commit ecc4c38

Browse files
committed
net: sockets: Add configurable option to provide raw POSIX API names
With CONFIG_NET_SOCKETS_POSIX_NAMES=y, "raw" POSIX names like socket(), recv(), close() will be exposed (using macro defines). The close() is the biggest culprit here, because in POSIX it applies to any file descriptor, but in this implementation - only to sockets. Signed-off-by: Paul Sokolovsky <[email protected]>
1 parent 4f76622 commit ecc4c38

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

include/net/socket.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@
77
#ifndef __NET_SOCKET_H
88
#define __NET_SOCKET_H
99

10+
#include <zephyr/types.h>
11+
#include <net/net_ip.h>
12+
1013
#ifdef __cplusplus
1114
extern "C" {
1215
#endif
1316

1417
int zsock_socket(int family, int type, int proto);
1518
int zsock_close(int sock);
1619

20+
#if defined(CONFIG_NET_SOCKETS_POSIX_NAMES)
21+
#define socket zsock_socket
22+
#define close zsock_close
23+
#endif
24+
1725
#ifdef __cplusplus
1826
}
1927
#endif

subsys/net/lib/sockets/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ menuconfig NET_SOCKETS
1414

1515
if NET_SOCKETS
1616

17+
config NET_SOCKETS_POSIX_NAMES
18+
bool "Standard POSIX names for Sockets API"
19+
default n
20+
help
21+
By default, Sockets API function are prefixed with `zsock_` to avoid
22+
namespacing issues. If this option is enabled, they will be provided
23+
with standard POSIX names like socket(), recv(), and close(), to help
24+
with porting existing code. Note that close() may require a special
25+
attention, as in POSIX it closes any file descriptor, while with this
26+
option enaled, it will still apply only to sockets.
27+
1728
config NET_DEBUG_SOCKETS
1829
bool "Debug BSD Sockets like API calls"
1930
default n

0 commit comments

Comments
 (0)