[Spread-users] Spread and select

Hua Zhong hzhong at gmail.com
Fri Apr 7 19:05:35 EDT 2006


Hi list,

I just started looking into spread and have a question: how do you use spread with select()?

It seems the only way to receive a message is either:

1. SP_receive(), which blocks until there is a message, which means you cannot do anything else in between.
2. SP_poll() and if it returns, do a SP_receive(). There are multiple problems:
    a. You'd have to have a poll & sleep loop. Not only inefficient, but also introduce high response latency.
    b. SP_receive() is blocking, i.e., if no message then it would block forever. It could happen if the message is gone before an
SP_poll and SP_receive. You may say it's application's responsibility to synchronize, but sometimes it's out of its control. If the
transport was UDP instead of TCP Linux kernel could discard the message any time between a poll and an actual receive. So it's never
a good idea to mix select/poll with blocking receive.

What I would like to have is like this:

If (select(fdset, timeout) > 0) {
        if (FD_ISSET(sp_mbox, fdset)) {
                if (SP_nb_receive(sp_mbox) > 0) {
                        // we have a message
                }
        }
}

It doesn't seem to be very difficult to do considering the mbox is actually a socket handle. I could certainly do a select on it
myself, and hack SP_receive to do a non-blocking mode read. But I'd like to understand why it's not provided as a standard API.
Thanks.

Please let me know your opinion, thanks.

Hua





More information about the Spread-users mailing list