[GAP] Asynchroneus IO on Mac OS X
Christfried Webers
christfried.webers at ieee.org
Fri Sep 8 09:02:16 CEST 2006
While porting an Ada program running on Solaris and Linux to Mac OS X,
I ran into the problem that I could not catch SIGIO signals via an
installed signal handler (protected procedure). Before joining the GAP, I
filed a report to ACT ([F411-002 public], see below), but as a public
member I had no way of figuring out what happened with it.
Therefore, I am still puzzled, whether there is any proper Ada way of
catching the SIGIO on Mac OS X?
As mentioned below, installing a handler via a C library call to
sigaction() can solve the problem but completely by-passes the Ada runtime
and that just doesn't feel right.
Best
Chris
P.S.: My question has some relation to the previous thread:
I choose asynchronous IO with signals in order to be able to properly
release (but not kill!) the reading task after a timeout if NO data is
coming in. With blocking IO, one just hangs on the IO call.
------------- excerpt of [F411-002 public] -------------------------
1.) It seems that pragma Attach_Handler does not
result in a SIGIO being caught. It works fine with
other signals though. (Installing a signal handler
for the signal via a C call to sigaction() from the
Ada main program installs a handler which catches
the SIGIO signal.)
I tested it via repeated
kill -s IO <process id>
kill -s USR1 <process id>
and only got
Got SIGUSR1, Counter = 1
Got SIGUSR1, Counter = 2
Got SIGUSR1, Counter = 3
...
------------------------------------
with Ada.Text_IO;
with Ada.Interrupts.Names;
with Signals;
procedure Demo is
use Ada.Text_IO;
use Ada.Interrupts;
use Ada.Interrupts.Names;
SIGIO_Name : aliased String := "SIGIO";
SIGIO_Monitor : Signals.Monitor(SIGIO, SIGIO_Name'Access);
SIGUSR1_Name : aliased String := "SIGUSR1";
SIGUSR1_Monitor : Signals.Monitor(SIGUSR1, SIGUSR1_Name'Access);
begin
loop
delay 1.0;
end loop;
end Demo;
package Signals is
use Ada.Interrupts, Ada.Interrupts.Names;
-- Must first unreserve this interrupt if using SIGINT
pragma Unreserve_All_Interrupts;
protected type Monitor (Signal : Interrupt_ID;
Name : access String) is
procedure Handler;
pragma Attach_Handler (Handler, Signal);
private
Counter : Natural := 0;
end Monitor;
end Signals;
with Ada.Text_IO;
package body Signals is
use Ada.Text_IO;
protected body Monitor is
procedure Handler is
begin
Counter := Counter + 1;
Put_Line ("Got " & Name.all &
", Counter = " & Counter'Img);
end Handler;
end Monitor;
end Signals;
----------------------------------------------------------------------
Christfried Webers Department of Information Engineering
Ph +61 2 6125 8602 Research School of Information Sciences & Engineering
Fax +61 2 6125 8660 and Department of Computer Science
Christfried.Webers at anu.edu.au Australian National University
More information about the GAP
mailing list