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
246
246
config NET_SOCKETPAIR
247
247
bool "Support for socketpair"
248
248
select PIPES
249
- depends on HEAP_MEM_POOL_SIZE != 0
250
249
help
251
250
Communicate over a pair of connected, unnamed UNIX domain sockets.
252
251
252
+ if NET_SOCKETPAIR
253
+
253
254
config NET_SOCKETPAIR_BUFFER_SIZE
254
255
int "Size of the intermediate buffer, in bytes"
255
256
default 64
256
257
range 1 4096
257
- depends on NET_SOCKETPAIR
258
258
help
259
259
Buffer size for socketpair(2)
260
260
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
+
261
281
config NET_SOCKETS_NET_MGMT
262
282
bool "Network management socket support [EXPERIMENTAL]"
263
283
depends on NET_MGMT_EVENT
Original file line number Diff line number Diff line change @@ -56,6 +56,11 @@ __net_socket struct spair {
56
56
uint8_t buf [CONFIG_NET_SOCKETPAIR_BUFFER_SIZE ];
57
57
};
58
58
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
+
59
64
/* forward declaration */
60
65
static const struct socket_op_vtable spair_fd_op_vtable ;
61
66
@@ -188,7 +193,9 @@ static void spair_delete(struct spair *spair)
188
193
189
194
/* ensure no private information is released to the memory pool */
190
195
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
192
199
k_object_free (spair );
193
200
#else
194
201
k_free (spair );
@@ -213,7 +220,14 @@ static struct spair *spair_new(void)
213
220
struct spair * spair ;
214
221
int res ;
215
222
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
217
231
struct z_object * zo = z_dynamic_object_create (sizeof (* spair ));
218
232
219
233
if (zo == NULL ) {
You can’t perform that action at this time.
0 commit comments