Signal and slot trouble

Peter Federighi pfederighi at yahoo.com
Sun Nov 21 00:05:32 PST 2010


So, I've been trying to come up with an nice way of dealing with POSIX/Linux
signals when I discovered std.signals.  It looked cool, and while it doesn't
provide exactly what I want to do (since I have to use global functions in
order to use sigaction), it's nice enough.  So here's a simplified form of
what I'm trying to do (it doesn't actually do anything).  It compiles fine,
but segfaults on the connect call.

Any ideas?
Thank you,
- Peter

import std.signals;
import std.stdio;

class SignalForwarder
    {
    mixin Signal!(int);
    }

SignalForwarder sigWinchSignal;	// Window size change signal
SignalForwarder sigAlrmSignal;	// Timer alarm signal

void main()
    {
    SigWinchHandler winch;
    SigAlrmHandler alrm;

    // put sigaction code here

    sigWinchSignal.connect(&winch.handler);
    sigAlrmSignal.connect(&alrm.handler);

    // do something here
    }

// the functions that get called via sigaction
void sigWinch(int signal)
    {
    sigWinchSignal.emit(signal);
    }

void sigAlrm(int signal)
    {
    sigAlrmSignal.emit(signal);
    }

// perhaps one of many functions I want called when a signal is raised
class SigWinchHandler
    {
    void handler(int signal)
	{
	writeln("WINCH");
	}
    }

class SigAlrmHandler
    {
    void handler(int signal)
	{
	writeln("ALRM");
	}
    }


More information about the Digitalmars-d-learn mailing list