[Spread-users] Spread and select

John Schultz jschultz at spreadconcepts.com
Mon Apr 10 11:59:02 EDT 2006

Hua Zhong wrote:

>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.

You can count on a mailbox being a socket descriptor in Spread.  If that 
isn't in the official documentation right now, then we'll be sure to add 
it with the new release.

>2. there is still not a non-blocking version SP_receive. As I explained earlier, it's not very nice to programers.
>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.

You are correct that right now there is no non-blocking version of 
SP_receive.  This was a decision made a long time ago in Spread's 
development.  The idea was that if there is activity on the file 
descriptor (i.e. - incoming data), then the entire incoming message 
should be there "soon."  It is true that this can cause blocking 
behavior if, for example, the TCP/IP link between the client and server 
is slow for some reason.

The real way to make SP_receive non-blocking is to have each connection 
store partial messages internally when it blocks until it has collected 
an entire message that it can deliver.  By default, the maximum Spread 
msg size is ~100K.  In the past, we were reluctant to complicate the 
client library further and either always allocate 100K per connection or 
dynamically allocate memory as necessary.

John Schultz
Spread Concepts LLC
Phn:  301 498 3233
Cell: 443 838 2200

More information about the Spread-users mailing list