examples/client_server_mp: add sigint handler to server

Message ID 1538047312-27063-1-git-send-email-rasland@mellanox.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series 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:21 a.m. UTC
  add sigint handler in the server application to stop and close ports

Signed-off-by: Raslan Darawsheh <rasland@mellanox.com>
---
 .../multi_process/client_server_mp/mp_server/main.c     | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
  

Comments

Bruce Richardson Sept. 27, 2018, 11:27 a.m. UTC | #1
On Thu, Sep 27, 2018 at 02:21:52PM +0300, Raslan Darawsheh wrote:
> add sigint handler in the server application to stop and close ports
> 
> Signed-off-by: Raslan Darawsheh <rasland@mellanox.com>
> ---
>  .../multi_process/client_server_mp/mp_server/main.c     | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
> 
> 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..2ba73c4 100644
> --- a/examples/multi_process/client_server_mp/mp_server/main.c
> +++ b/examples/multi_process/client_server_mp/mp_server/main.c
> @@ -29,14 +29,15 @@
>  #include <rte_mbuf.h>
>  #include <rte_ether.h>
>  #include <rte_interrupts.h>
> -#include <rte_ethdev.h>
> +
>  #include <rte_byteorder.h>
>  #include <rte_malloc.h>
>  #include <rte_string_fns.h>
> -
> +#include <rte_ethdev.h>
>  #include "common.h"
>  #include "args.h"

Why the moving of the ethdev header include?
  

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..2ba73c4 100644
--- a/examples/multi_process/client_server_mp/mp_server/main.c
+++ b/examples/multi_process/client_server_mp/mp_server/main.c
@@ -29,14 +29,15 @@ 
 #include <rte_mbuf.h>
 #include <rte_ether.h>
 #include <rte_interrupts.h>
-#include <rte_ethdev.h>
+
 #include <rte_byteorder.h>
 #include <rte_malloc.h>
 #include <rte_string_fns.h>
-
+#include <rte_ethdev.h>
 #include "common.h"
 #include "args.h"
 #include "init.h"
+#include<signal.h>
 
 /*
  * When doing reads from the NIC or the client queues,
@@ -264,9 +265,21 @@  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;