Skip to content

socketpair improvements #54458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions samples/net/sockets/socketpair/Makefile.posix
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
#
# SPDX-License-Identifier: Apache-2.0
#
socketpair_example: src/socketpair_example.c
$(CXX) $^ -o $@ -lpthread
socketpair_example: src/main.c
$(CC) $^ -o $@ -lpthread
71 changes: 31 additions & 40 deletions samples/net/sockets/socketpair/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,27 @@ Build the Zephyr version of the sockets/echo application like this:
:goals: build
:compact:

After the sample starts, several clients thread are spawned and each client
thread sends a fixed number of messages to the server (main). Each client
sends a message (it's name) to the server.
After the sample starts, several client threads are spawned. Each client
thread sends a fixed number of messages to the server (main).

.. code-block:: console

*** Booting Zephyr OS build v2.3.0-rc1-215-g0e36f9686836 ***
Alpha: socketpair: 3 <=> 4
Bravo: socketpair: 5 <=> 7
Charlie: socketpair: 8 <=> 9
Charlie closed fd 9
fd: 8: read 21 bytes
fd: 8: hung up
main: closed fd 8
joined Charlie
Alpha closed fd 4
fd: 3: read 15 bytes
fd: 3: hung up
main: closed fd 3
joined Alpha
Bravo closed fd 7
fd: 5: read 15 bytes
fd: 5: hung up
main: closed fd 5
joined Bravo
finished!
*** Booting Zephyr OS build v3.3.0-rc1-97-g432ff20a72e1 ***
setting-up
Alpha: socketpair: 4 <=> 3
Bravo: socketpair: 6 <=> 5
Charlie: socketpair: 8 <=> 7
main: read 'Alpha' on fd 4
main: read 'Bravo' on fd 6
main: read 'Charlie' on fd 8
main: read 'Alpha' on fd 4
main: read 'Bravo' on fd 6
main: read 'Charlie' on fd 8
main: read 'Alpha' on fd 4
main: read 'Bravo' on fd 6
main: read 'Charlie' on fd 8
tearing-down
SUCCESS

Running application on POSIX Host
=================================
Expand All @@ -76,26 +71,22 @@ To run:

.. code-block:: console

$ ./socketpair_example
./socketpair_example
setting-up
Alpha: socketpair: 3 <=> 4
Bravo: socketpair: 5 <=> 6
Charlie: socketpair: 7 <=> 8
Alpha closed fd 4
fd: 3: read 15 bytes
fd: 3: hung up
main: closed fd 3
joined Alpha
fd: 5: read 15 bytes
fd: 5: hung up
Bravo closed fd 6
main: closed fd 5
joined Bravo
Charlie closed fd 8
fd: 7: read 21 bytes
fd: 7: hung up
main: closed fd 7
joined Charlie
finished!
main: read 'Alpha' on fd 3
main: read 'Bravo' on fd 5
main: read 'Charlie' on fd 7
main: read 'Alpha' on fd 3
main: read 'Alpha' on fd 3
main: read 'Bravo' on fd 5
main: read 'Charlie' on fd 7
main: read 'Bravo' on fd 5
main: read 'Charlie' on fd 7
tearing-down
SUCCESS

As can be seen, the behavior of the application is approximately the same as
the Zephyr version.
15 changes: 5 additions & 10 deletions samples/net/sockets/socketpair/prj.conf
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
# Provide some heap space
CONFIG_HEAP_MEM_POOL_SIZE=2048

# Networking config
CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y
# socketpair dependencies
CONFIG_POSIX_API=y
CONFIG_NET_SOCKETPAIR=y

# Network driver config
# Networking config (network subsystem dependencies)
CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS=y
CONFIG_TEST_RANDOM_GENERATOR=y

# Use Portable threads
CONFIG_PTHREAD_IPC=y
CONFIG_POSIX_CLOCK=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y
14 changes: 9 additions & 5 deletions samples/net/sockets/socketpair/sample.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
sample:
description: BSD Sockets API TCP socketpair sample
name: socket_socketpair
description: Socketpair sample
name: socketpair
common:
tags: net socket posix
harness: net
arch_exclude: posix
integration_platforms:
- mps2_an385
tests:
sample.net.sockets.socketpair:
harness: net
tags: net socket
sample.net.sockets.socketpair: {}
Loading