[v3] examples/client_server_mp: add sigint handler to server

Message ID 1538049104-23277-1-git-send-email-rasland@mellanox.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v3] examples/client_server_mp: add sigint handler to server |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Raslan Darawsheh Sept. 27, 2018, 11:51 a.m. UTC
  add sigint handler in the server application to stop and close ports

Signed-off-by: Raslan Darawsheh <rasland@mellanox.com>

---
v2:
	- fix includes order

v3:
	- fix spacing
---
---
 examples/multi_process/client_server_mp/mp_server/main.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
  

Comments

Thomas Monjalon Nov. 4, 2018, 8:42 p.m. UTC | #1
27/09/2018 13:51, Raslan Darawsheh:
> add sigint handler in the server application to stop and close ports
> 
> Signed-off-by: Raslan Darawsheh <rasland@mellanox.com>

Applied, thanks
  

Patch

diff --git a/examples/multi_process/client_server_mp/mp_server/main.c b/examples/multi_process/client_server_mp/mp_server/main.c
index 93a9a08..0ddc63e 100644
--- a/examples/multi_process/client_server_mp/mp_server/main.c
+++ b/examples/multi_process/client_server_mp/mp_server/main.c
@@ -12,6 +12,7 @@ 
 #include <sys/queue.h>
 #include <errno.h>
 #include <netinet/ip.h>
+#include <signal.h>
 
 #include <rte_common.h>
 #include <rte_memory.h>
@@ -264,9 +265,23 @@  do_packet_forwarding(void)
 	}
 }
 
+static void
+signal_handler(int signal)
+{
+	uint16_t port_id;
+
+	if (signal == SIGINT)
+		RTE_ETH_FOREACH_DEV(port_id) {
+			rte_eth_dev_stop(port_id);
+			rte_eth_dev_close(port_id);
+		}
+	exit(0);
+}
+
 int
 main(int argc, char *argv[])
 {
+	signal(SIGINT, signal_handler);
 	/* initialise the system */
 	if (init(argc, argv) < 0 )
 		return -1;