Running demo program:
C:\CCStudio_v3.3\ndk_2_0_0\packages\ti\ndk\example\network\helloWorld
provided by NDK2.0.0, I found the function dtask_udp_hello() registered by the following code:
hHello = DaemonNew( SOCK_DGRAM, 0, 7, dtask_udp_hello, OS_TASKPRINORM, OS_TASKSTKNORM, 0, 1 )
could never be called. Is there anybody who meets the same problem?
I have replaced nettool.lib with NDK source code to debug into source code of DaemonNew() function to trace this problem, and I found the following line in DaemonNew.c:
// Update the fdPoll array
pollitem[i].fd = drec[i].s;
if( drec[i].Type && drec[i].TasksSpawned < drec[i].MaxSpawn )
pollitem[i].eventsRequested = POLLIN; //…….. Label 1
else
pollitem[i].eventsRequested = 0; //…….. Label 2
// Leave our lock
SemPost( hDSem );
// Poll with a timeout of 10 second - to try and catch
// synchronization error
if( fdPoll( pollitem, DAEMON_MAXRECORD, 10000 ) == SOCKET_ERROR )
break;
// Enter our lock
SemPend( hDSem, SEM_FOREVER );
// Spawn tasks for any active sockets
for( i=0; i<DAEMON_MAXRECORD; i++ )
{
// If no poll results or the drec has been freed, skip it
if( !pollitem[i].eventsDetected || !drec[i].Type )
continue; //…….. Label 3
// If the socket is invalid, close it
if( pollitem[i].eventsDetected & POLLNVAL ) //…….. Label 4
{
fdClose( drec[i].s);
drec[i].s = INVALID_SOCKET;
continue;
}
Label 1 and Label 2 will be executed alternatively, while Label 3 could be executed DAEMON_MAXRECORD (which is 12) times, but Label 4 could never be executed. This is the cause of the failure mentioned above, but why?