Skip to content

Commit 16a54f2

Browse files
jukkarcarlescufi
authored andcommitted
net: sockets: Refactor accept() to support objcore better
If user has not supplied address pointer when calling accept(), then we would not be able to figure out the used socket domain properly. But as there is now SO_DOMAIN option supported, use that to get the correct socket domain. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 4c88169 commit 16a54f2

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

subsys/net/lib/sockets/socket_obj_core.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,11 @@ int sock_obj_core_alloc(int sock, struct net_socket_register *reg,
158158
return ret;
159159
}
160160

161-
int sock_obj_core_alloc_find(int sock, int new_sock, int family, int type)
161+
int sock_obj_core_alloc_find(int sock, int new_sock, int type)
162162
{
163163
struct net_socket_register *reg = NULL;
164+
socklen_t optlen = sizeof(int);
165+
int family;
164166
int ret;
165167

166168
if (new_sock < 0) {
@@ -172,6 +174,12 @@ int sock_obj_core_alloc_find(int sock, int new_sock, int family, int type)
172174
goto out;
173175
}
174176

177+
ret = zsock_getsockopt(sock, SOL_SOCKET, SO_DOMAIN, &family, &optlen);
178+
if (ret < 0) {
179+
NET_ERR("Cannot get socket domain (%d)", -errno);
180+
goto out;
181+
}
182+
175183
ret = sock_obj_core_alloc(new_sock, reg, family, type, ret);
176184
if (ret < 0) {
177185
NET_ERR("Cannot allocate core object for socket %d (%d)",

subsys/net/lib/sockets/sockets.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -684,9 +684,7 @@ int z_impl_zsock_accept(int sock, struct sockaddr *addr, socklen_t *addrlen)
684684

685685
new_sock = VTABLE_CALL(accept, sock, addr, addrlen);
686686

687-
if (addr) {
688-
(void)sock_obj_core_alloc_find(sock, new_sock, addr->sa_family, SOCK_STREAM);
689-
}
687+
(void)sock_obj_core_alloc_find(sock, new_sock, SOCK_STREAM);
690688

691689
return new_sock;
692690
}

subsys/net/lib/sockets/sockets_internal.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ size_t msghdr_non_empty_iov_count(const struct msghdr *msg);
8282
#if defined(CONFIG_NET_SOCKETS_OBJ_CORE)
8383
int sock_obj_core_alloc(int sock, struct net_socket_register *reg,
8484
int family, int type, int proto);
85-
int sock_obj_core_alloc_find(int sock, int new_sock, int family, int type);
85+
int sock_obj_core_alloc_find(int sock, int new_sock, int type);
8686
int sock_obj_core_dealloc(int sock);
8787
void sock_obj_core_update_send_stats(int sock, int bytes);
8888
void sock_obj_core_update_recv_stats(int sock, int bytes);
@@ -100,12 +100,10 @@ static inline int sock_obj_core_alloc(int sock,
100100
return -ENOTSUP;
101101
}
102102

103-
static inline int sock_obj_core_alloc_find(int sock, int new_sock,
104-
int family, int type)
103+
static inline int sock_obj_core_alloc_find(int sock, int new_sock, int type)
105104
{
106105
ARG_UNUSED(sock);
107106
ARG_UNUSED(new_sock);
108-
ARG_UNUSED(family);
109107
ARG_UNUSED(type);
110108

111109
return -ENOTSUP;

0 commit comments

Comments
 (0)