[Spread-users] Spread and select
mgillen at bbn.com
Sat Apr 8 13:48:54 EDT 2006
Hua Zhong wrote:
> Thanks for the reply , see inline.
>> Hua Zhong wrote:
>>> 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.
>>> Please let me know your opinion, thanks.
>> There's an example of using select() with the mbox fd in the
>> event system that is provided with Spread. You don't have to
>> hack SP_receive at all (that's the whole point of using
>> select()! ). See the E_handle_events function of events.c
> Good, but there are a couple of issues:
> 1. it's not documented, thus making me wonder if it's officially supported feature. In fact, there is not even a SP_mailbox_to_fd
> kind of helper. How could one assume mailbox == fd? It's implementation details that could change anytime, and nothing to depend on.
I'll admit that I don't know what the implications are on Windows. However,
mailbox==fd should be a safe assumption on unix systems.
> 2. there is still not a non-blocking version SP_receive. As I explained earlier, it's not very nice to programers.
But it's perfectly valid to call select() on a non-blocking file descriptor.
Just I'm not sure I understand where you think the problem is.
> I just checked the spread code (v3.17.3) and find the following in sp.c:
> while(((ret = recv( mbox, &scat_mess->elements[scat_index].buf[byte_index], to_read, 0 )) == -1 )
> && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)) )
> This is very weird. If it's a blocking socket, it should never return EGAIN. If it's a non-blocking socket, the above effectily will
> spin forever until there is data.
I'm not sure what that code is supposed to do, but EAGAIN is only one
possible cause of recv() returning -1. If you check the docs for SP_receive():
"The SP_receive function will block if no messages are available."
> Anyway, I think it would be a great improvement if non-blocking API could be provided.
More information about the Spread-users