This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/DK-TM4C129X: Listening with fdPoll()

Part Number: DK-TM4C129X

Tool/software: TI-RTOS

In the NDK manual, fdPoll() describes data file descriptor interactions well, but there doesn't appear to be a description of how fdPoll() deals with listener FD's.  What are the semantics (what events to specify/examine) for fdPoll() when monitoring listener FD's?  Is it even legal to use fdPoll() for listening?  What about looking for POLLIN, then attempting accept() for listener FD's returning that event?

  • Hi Leo,

    Yes, you can use fdPoll on listening sockets.  This is what the NDK's daemon feature does.

    You can see the code for this in ti/ndk/nettools/daemon/daemon.c, in the function  daemon() function.

    The sockets are set to listen around line 395:

                    /* If the socket is bound and TCP, start listening */
                    if( drec[i].s != INVALID_SOCKET && drec[i].Type != SOCK_DGRAM )
                    {
                        if( listen( drec[i].s, drec[i].MaxSpawn ) < 0 )

    The call to fdPoll is around line 418:

            /* Poll with a timeout of 10 second - to try and catch */
            /* synchronization error */
            if( fdPoll( pollitem, DAEMON_MAXRECORD, 10000 ) == SOCKET_ERROR )
                break;

    If "everything's OK" then it calls accept on the socket that was evented:

                if( pollitem[i].eventsDetected & POLLIN )
                {
                    if( drec[i].Type == SOCK_DGRAM )
                    {
                        tsock = drec[i].s;
                        closeSock = 0;
                    }
                    else
                    {
                        tsock = accept( drec[i].s, 0, 0 );
                        closeSock = 1;
                    }

    Steve