understanding eloop.c

Dan Williams dcbw
Mon Nov 17 07:38:04 PST 2008

On Mon, 2008-11-17 at 13:08 +0100, Arne Keller wrote:
> Hello @ all,
> I'm trying so understand the hostapd code for a while now.
> Step by step it's getting more clear to me how everything is working.
> The Problem I'm facing right now is that I don't understand the function 
> of eloop completely.
> I figured out that in eloop.c the overall eventloop is implemented. But 
> I don't understand the behavior of eloop_run(). Everything starts here 
> an every function goes bak to this point. What I don't see is how 
> functions are called again after they are exited, I don't understand how 
> functions are called from here either.

It's a normal event loop.  It sits in select(), waiting for the ability
to read or write on any of the watched file descriptors.  Additionally,
there is timeout support, such that other code can say "wake me up in 10

So, the select() will sit there until either a timer fires, or there's
something to be done on a socket.  The code registers handlers with the
eloop that should be run on various conditions.  When that condition
becomes true, the eloop code will call any handlers registered for that

	/* check if some registered timeouts have occurred */
	if (eloop.timeout) {
		struct eloop_timeout *tmp;

		if (!os_time_before(&now, &eloop.timeout->time)) {
			tmp = eloop.timeout;
			eloop.timeout = eloop.timeout->next;
Timer handler functions called from here ^^^^^^



	eloop_sock_table_dispatch(&eloop.readers, rfds);
	eloop_sock_table_dispatch(&eloop.writers, wfds);
	eloop_sock_table_dispatch(&eloop.exceptions, efds);

Socket condition handlers called from here ^^^^^

When the handlers are done handling whatever condition they are meant
for, they eventually return back to eloop_run(), which then waits for
another condition to occur or timer to fire or signal to be raised.


More information about the Hostap mailing list