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

Message ID 1538047613-27309-1-git-send-email-rasland@mellanox.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series [v2] 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:26 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
---
---
 examples/multi_process/client_server_mp/mp_server/main.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
  

Comments

Thomas Monjalon Sept. 27, 2018, 11:36 a.m. UTC | #1
27/09/2018 13:26, Raslan Darawsheh:
> v2:
> 	- fix includes order

I'm afraid you will need a v3 to fix spacing :)

> --- a/examples/multi_process/client_server_mp/mp_server/main.c
> +++ b/examples/multi_process/client_server_mp/mp_server/main.c
> @@ -37,6 +37,7 @@
>  #include "common.h"
>  #include "args.h"
>  #include "init.h"
> +#include<signal.h>

A space is missing here.

> +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[])

A blank line is missing between the functions.
  
Bruce Richardson Sept. 27, 2018, 12:30 p.m. UTC | #2
On Thu, Sep 27, 2018 at 01:36:06PM +0200, Thomas Monjalon wrote:
> 27/09/2018 13:26, Raslan Darawsheh:
> > v2:
> > 	- fix includes order
> 
> I'm afraid you will need a v3 to fix spacing :)
> 
> > --- a/examples/multi_process/client_server_mp/mp_server/main.c
> > +++ b/examples/multi_process/client_server_mp/mp_server/main.c
> > @@ -37,6 +37,7 @@
> >  #include "common.h"
> >  #include "args.h"
> >  #include "init.h"
> > +#include<signal.h>
> 
> A space is missing here.
> 

Also, the norm in DPDK is to list all standard headers first, then the DPDK
headers and finally the local headers. "signal.h" therefore should be
further up in the file, with the first group.

> > +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[])
> 
> A blank line is missing between the functions.
> 
>
  
Thomas Monjalon Sept. 27, 2018, 12:48 p.m. UTC | #3
27/09/2018 14:30, Bruce Richardson:
> On Thu, Sep 27, 2018 at 01:36:06PM +0200, Thomas Monjalon wrote:
> > 27/09/2018 13:26, Raslan Darawsheh:
> > > v2:
> > > 	- fix includes order
> > 
> > I'm afraid you will need a v3 to fix spacing :)
> > 
> > > --- a/examples/multi_process/client_server_mp/mp_server/main.c
> > > +++ b/examples/multi_process/client_server_mp/mp_server/main.c
> > > @@ -37,6 +37,7 @@
> > >  #include "common.h"
> > >  #include "args.h"
> > >  #include "init.h"
> > > +#include<signal.h>
> > 
> > A space is missing here.
> > 
> 
> Also, the norm in DPDK is to list all standard headers first, then the DPDK
> headers and finally the local headers. "signal.h" therefore should be
> further up in the file, with the first group.

I think he did that already in v3 :)
  
Bruce Richardson Sept. 27, 2018, 2:37 p.m. UTC | #4
On Thu, Sep 27, 2018 at 02:48:38PM +0200, Thomas Monjalon wrote:
> 27/09/2018 14:30, Bruce Richardson:
> > On Thu, Sep 27, 2018 at 01:36:06PM +0200, Thomas Monjalon wrote:
> > > 27/09/2018 13:26, Raslan Darawsheh:
> > > > v2:
> > > > 	- fix includes order
> > > 
> > > I'm afraid you will need a v3 to fix spacing :)
> > > 
> > > > --- a/examples/multi_process/client_server_mp/mp_server/main.c
> > > > +++ b/examples/multi_process/client_server_mp/mp_server/main.c
> > > > @@ -37,6 +37,7 @@
> > > >  #include "common.h"
> > > >  #include "args.h"
> > > >  #include "init.h"
> > > > +#include<signal.h>
> > > 
> > > A space is missing here.
> > > 
> > 
> > Also, the norm in DPDK is to list all standard headers first, then the DPDK
> > headers and finally the local headers. "signal.h" therefore should be
> > further up in the file, with the first group.
> 
> I think he did that already in v3 :)
> 
Yes, he did. I just need the ability to read all mails in parallel, while
also typing up new ones. :-)
  

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..16aa944 100644
--- a/examples/multi_process/client_server_mp/mp_server/main.c
+++ b/examples/multi_process/client_server_mp/mp_server/main.c
@@ -37,6 +37,7 @@ 
 #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;