[Spread-users] how to check for available messages

Taj Khattra taj.khattra at pobox.com
Thu Mar 18 20:06:58 EST 2004


> like any other socket handle.  There's also the SP_poll() function, but it's
> not particularly good even for polling because it doesn't return an error
> code if the client has gotten disconnected (it returns 0 then, so a "polling
> loop" just using SP_poll() will never know it if the client gets
> disconnected).

i modified my local copy of SP_poll() to work around this:

instead of returning the #bytes available with ioctl(), it returns
true/false by using a non-blocking select().  if the client gets
disconnected, select() returns readable but the next send() or
recv() will return -1 w/EPIPE.

	FD_ZERO(&rset);
	FD_SET(mbox, &rset);
	tv.tv_sec = tv.tv_usec = 0;
	ret = select(mbox+1, &rset, 0, 0, &tv);
	if (ret < 0) return ILLEGAL_SESSION;
	else return ret;

haven't noticed any problems so far...




More information about the Spread-users mailing list