[Spread-users] SP_poll() result when spread daemon is dead

Colin Meyer cmeyer at helvella.org
Thu Sep 20 18:23:25 EDT 2007


On Thu, Sep 20, 2007 at 03:48:50PM -0500, Matt Garman wrote:
> 
>     (2) Use either your system's select() call or Spread's event
> interface to watch for activity on the mbox.  You can use this to
> detect anything that happens to an mbox, including disconnect from the
> daemon.

This approach works well for me. I call select() just before calling
SP_poll(). If select() shows the socket as readable, but SP_poll()
(ioctl()) says that there are zero bytes available, then I'm
disconnected. Thanks for the idea.

I wonder why this isn't just done within SP_poll()?

My coworker, Dave Olszewski, crafted a quick patch to SP_poll that
should do the trick (untested):

     /* check mbox to see if it has input. */
     FD_ZERO(&rfds);
     FD_SET(mbox, &rfds);
     /* don't wait */
     tv.tv_sec = 0;
     tv.tv_usec = 0;
     ret = select(mbox+1, &rfds, NULL, NULL, &tv);
     if (ret == -1) return( ILLEGAL_SESSION );
     if (ret) { /* FD_ISSET(mbox, &rfds) will be true. */
         ret = ioctl( mbox, FIONREAD, &num_bytes);
         /* less than zero is an error, zero means socket is closed */
         if( ret <= 0 ) return( ILLEGAL_SESSION );
         return( num_bytes );
     }
     else /* nothing there */
         return( 0 );

We'd rather not run a modified spread system, so for now we are
just calling select() in the application code.

-Colin.




More information about the Spread-users mailing list