This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: FreeBSD problem with UDP sockets


>>>>> "Andrew" == Andrew Lunn <andrew@lunn.ch> writes:

    >> if( result < 0 )
    >> {
    >> FATALSYS(("Error in: select(%d)", socketM));
    >> }
    >> 
    >> int isSet = FD_ISSET(socketM, &readfds);

    Andrew> Here is your problem. With passing {0,0} for waitTime, you
    Andrew> are doing a poll. If there is nothing to receive on the
    Andrew> socket, select will return 0, but it is not updating the
    Andrew> readfds. Read the code in
    Andrew> packages/io/fileio/current/src/select.cxx.

    Andrew> This might be an eCos bug. It might not be as well.  The Posix
    Andrew> standard at not 100% clear on this issue when i read
    Andrew> it. http://www.opengroup.org/onlinepubs/009695399/toc.htm

    Andrew>     On failure, the objects pointed to by the readfds, writefds, and
    Andrew>     errorfds arguments shall not be modified. If the timeout interval
    Andrew>     expires without the specified condition being true for any of the
    Andrew>     specified file descriptors, the objects pointed to by the readfds,
    Andrew>     writefds, and errorfds arguments shall have all bits set to 0.

    Andrew> When you have passed a timeout of {0,0} you are doing a
    Andrew> poll. So the timeout has not expired. However, we are not
    Andrew> returning an error code so it could also be said we are
    Andrew> not in the failure case either.

>From my reading of the standard, specifically the "Return Value"
section, a poll is not a failure condition:

    Upon successful completion, the pselect() and select() functions
    shall return the total number of bits set in the bit masks.
    Otherwise, -1 shall be returned, and errno shall be set to
    indicate the error.

Since in this case we are not returning -1 it is not a failure, and
hence the fd_sets should be cleared. There is also some relevant text
in the Linux select_tut man page:

    If select timed out, then the file descriptors sets should be all
    empty (but may not be on some systems). However the return value
    will definitely be zero.

That man page is not authorative, but does suggest that clearing the
fd_sets is the right thing to do even though not all systems work that
way.

I think the current eCos behaviour is actually more sensible because
it means you only need to reset the fd_sets when there has been I/O,
not after every unsuccessful poll. But the standard says otherwise.

The following (untested) would probably fix the problem, but I'll
leave it to Nick to decide what to about it.

Bart

Index: select.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/fileio/current/src/select.cxx,v
retrieving revision 1.12
diff -u -r1.12 select.cxx
--- select.cxx	2 Aug 2004 11:24:48 -0000	1.12
+++ select.cxx	18 Aug 2004 20:54:16 -0000
@@ -206,7 +206,7 @@
         if( error )
             break;
         
-        if (num)
+        if (num || (0 == ticks))
         {
             // Found something, update user's sets
             if (in)  FD_COPY( &in_res, in );
@@ -248,13 +248,6 @@
                 // Nothing found, see if we want to wait
                 if (tv)
                 {
-                    // Special case of "poll"
-                    if (ticks == 0)
-                    {
-                        error = EAGAIN;
-                        break;
-                    }
-
                     ticks += Cyg_Clock::real_time_clock->current_value();
                 
                     if( !selwait.wait( ticks ) )

-- 
Bart Veer                       eCos Configuration Architect
http://www.ecoscentric.com/     The eCos and RedBoot experts

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]