AnsweredAssumed Answered

Lwip problem - telnet demo - socket close + open causes error/kernel panic.

Question asked by ExtrasensorySystems on Jul 6, 2011
Latest reply on Jul 18, 2011 by CraigG

Dear All,

 

I have the lwip ethernet demo running on my own BF518F board.

I can connect via TCP port 23 (telnet) and each connection from telnet creates a new thread.
All of them work fine.

 

BUT When I close the first Telnet app on the PC, then tries to connect with one more Telnet -
the system generates an error, which is default handled as kernel panic.

 

I checked the socket is closed just before the thread exits ... I assume the exit of the run function should handle anything else.

 

When I open the NEXT Telnet connection, the application goes dead in Kernel Panic.

 

Kent

 

Create:

     for ( ;; )  {
         struct sockaddr cliaddr;
         int clilen;
         int iSocket;

         iSocket = accept (listenfd, &cliaddr, &clilen);
         if ( -1 == iSocket ) {
             printf ( "Call to accept() failed.\n" );
             abort();
         }

         printf("Incoming connection: %d\n",iSocket);
        
          VDK_ThreadCreationBlock TCB = {
              kCommand_Thread,
              (VDK_ThreadID)0,
              0,
              (VDK_Priority)0,
              (void *) iSocket,
              0
          };

          if ( UINT_MAX == VDK_CreateThreadEx ( &TCB ) ) {
              printf( "Call to VDK_CreateThreadEx()failed.\n" );
              abort();
         }
      }
   }

 

 

------------------ thread run function -----

void
Command_Thread_RunFunction(void **inPtr) {
static char *pszWelcome = "Hi, I am the BF518 Blackfin board. \xa\xd - For now, I add 1 char to what you type Go ahead.\xa\xd";
   if ( 0 >= send ( m_iSocket, pszWelcome, strlen ( pszWelcome ), 0 ) )
      return;
     while (1) {
        int iCount;
        if ( ( iCount = recv ( m_iSocket, m_vInBuf, sizeof ( m_vInBuf ) / sizeof ( char ), 0 ) ) >= 1 ) {
           int iCharNum;
           char c;

           for ( iCharNum = 0; iCharNum < iCount; ++iCharNum ) {
              c = m_vInBuf [ iCharNum ];

              if ( ( c >= 'A' && c <= 'Y' ) || ( c >= 'a' && c <= 'y' ) )
                 ++c;
              else if ( c == 'Z' || c == 'z' )
                 c -= ( 'Z' - 'A' );
              m_vOutBuf [ iCharNum ] = c;
           }
           if ( send (m_iSocket, m_vOutBuf, iCount, 0) <= 0 )  break;
      } else {
         break;
      }
   }
   close ( m_iSocket );
}

Outcomes