File tree Expand file tree Collapse file tree 2 files changed +38
-4
lines changed Expand file tree Collapse file tree 2 files changed +38
-4
lines changed Original file line number Diff line number Diff line change @@ -246,18 +246,38 @@ config NET_SOCKETS_CAN_RECEIVERS
246246config NET_SOCKETPAIR
247247 bool "Support for socketpair"
248248 select PIPES
249- depends on HEAP_MEM_POOL_SIZE != 0
250249 help
251250 Communicate over a pair of connected, unnamed UNIX domain sockets.
252251
252+ if NET_SOCKETPAIR
253+
253254config NET_SOCKETPAIR_BUFFER_SIZE
254255 int "Size of the intermediate buffer, in bytes"
255256 default 64
256257 range 1 4096
257- depends on NET_SOCKETPAIR
258258 help
259259 Buffer size for socketpair(2)
260260
261+ choice
262+ prompt "Memory management for socketpair"
263+ default NET_SOCKETPAIR_HEAP if HEAP_MEM_POOL_SIZE != 0
264+
265+ config NET_SOCKETPAIR_STATIC
266+ bool "Pre-allocate memory statically"
267+
268+ config NET_SOCKETPAIR_HEAP
269+ bool "Use heap for allocating socketpairs"
270+ depends on HEAP_MEM_POOL_SIZE != 0
271+
272+ endchoice
273+
274+ if NET_SOCKETPAIR_STATIC
275+ config NET_SOCKETPAIR_MAX
276+ int "How many socketpairs to pre-allocate"
277+ default 1
278+ endif
279+ endif
280+
261281config NET_SOCKETS_NET_MGMT
262282 bool "Network management socket support [EXPERIMENTAL]"
263283 depends on NET_MGMT_EVENT
Original file line number Diff line number Diff line change @@ -56,6 +56,11 @@ __net_socket struct spair {
5656 uint8_t buf [CONFIG_NET_SOCKETPAIR_BUFFER_SIZE ];
5757};
5858
59+ #ifdef CONFIG_NET_SOCKETPAIR_STATIC
60+ K_MEM_SLAB_DEFINE_STATIC (spair_slab , sizeof (struct spair ), CONFIG_NET_SOCKETPAIR_MAX * 2 ,
61+ __alignof__(struct spair ));
62+ #endif /* CONFIG_NET_SOCKETPAIR_STATIC */
63+
5964/* forward declaration */
6065static const struct socket_op_vtable spair_fd_op_vtable ;
6166
@@ -188,7 +193,9 @@ static void spair_delete(struct spair *spair)
188193
189194 /* ensure no private information is released to the memory pool */
190195 memset (spair , 0 , sizeof (* spair ));
191- #ifdef CONFIG_USERSPACE
196+ #ifdef CONFIG_NET_SOCKETPAIR_STATIC
197+ k_mem_slab_free (& spair_slab , (void * * ) & spair );
198+ #elif CONFIG_USERSPACE
192199 k_object_free (spair );
193200#else
194201 k_free (spair );
@@ -213,7 +220,14 @@ static struct spair *spair_new(void)
213220 struct spair * spair ;
214221 int res ;
215222
216- #ifdef CONFIG_USERSPACE
223+ #ifdef CONFIG_NET_SOCKETPAIR_STATIC
224+
225+ res = k_mem_slab_alloc (& spair_slab , (void * * ) & spair , K_NO_WAIT );
226+ if (res != 0 ) {
227+ spair = NULL ;
228+ }
229+
230+ #elif CONFIG_USERSPACE
217231 struct z_object * zo = z_dynamic_object_create (sizeof (* spair ));
218232
219233 if (zo == NULL ) {
You can’t perform that action at this time.
0 commit comments