1
votes

http://linux.die.net/man/2/signal

"signal() sets the disposition of the signal signum to handler, which is either SIG_IGN, SIG_DFL, or the address of a programmer-defined function (a "signal handler")."

I find the description of what it does to be vague (new to network and linux programming). Is this some sort of callback setting function? Right now my code (which I haven't compiled yet) is using it like:

signal( SIGIO, readMessage );

Where readMessage is a function. SIGIO is defined as:

SIGPOLL is the signal sent to a process when an asynchronous I/O event occurs.

So putting this all together, I can only guess that when some asynchronous I/O event occurs, the function readMessage( int ) is called? Is this like slots/signals in Qt?

One other question I have is, what exactly is considered an I/O event in the context of network programming? Is it an accept call that returns?

1
You probably want to look into the aio functions such as aio_read, aio_write and other from the aio.h header. - Zan Lynx

1 Answers

0
votes

On *nix, signals are callbacks from the kernel to userspace. They are somewhat similar to interrupts, which can be thought of as callbacks from the hardware to the operating system.

They are more alike events in event-based systems than signals/slots in Qt. In Qt, a component can emit signals, which can be received by several slots in other components, and the program sets the connections between signals and slots, In other systems (Xlib, Win32), the program receives predetermined events from the system.

*nix supports blocking and non-blocking sockets. The poll() and select() system calls allow a program to wait for an I/O event. As an alternative to poll()/select(), BSD and Linux can also be made to send a signal (SIGIO by default) when an I/O event occurs, achieving a form of asynchronous I/O. More information can be found in the manpage for fcntl(), looking for F_SETFL, F_SETOWN, F_SETSIG.