Skip to content
Advertisement

Using a signal handler to process datas received from a fifo

I am writing a simple client/server communication with fifo but i am stuck at using a signal handler to process client request.

The server open a fifo in readonly and non blocking mode, read datas received and writes back some datas to the client fifo.

And this actually works fine when there is no signal handler on the server side. Here is the main code for both sides.

Server :

JavaScript

Client :

JavaScript

Everything works as expected ( even if all errors are not properly handled, this is just a sample code to demonstrate that this is possible).

The problem is that the handler ( not shown here, but it only print a message on the terminal with the signal received ) is never called when the client write datas to the fifo. Beside, i have check that if i send a kill -SIGIO to the server from a bash ( or from elsewhere ) the signal handler is executed.

Thanks for your help.

Advertisement

Answer

Actually, i missed the 3 following lines on the server side :

JavaScript

The last point was important because the default signal sent was 0 in my case, so i had to set it explicity to SIGIO to make things works. Here is the output of the server side :

JavaScript

Now, i guess it’s possible to handle the request inside the handler by moving what is inside the while loop into the requestHandler function.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement