• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Microcontrollers » Stellaris® ARM® Microcontrollers » Stellaris® ARM® LM3S Microcontrollers Forum » LWIP hangs in close(_socket) ( with socket API )
Share
Stellaris® ARM® Microcontrollers
  • Forum
Options
  • Subscribe via RSS

Forums

LWIP hangs in close(_socket) ( with socket API )

This question is not answered
Mikhail Mushkatblat
Posted by Mikhail Mushkatblat
on Feb 02 2012 16:34 PM
Prodigy10 points

As per subject line

Enviroment IAR 6.30+on TI LM3S9B96 (demo board) + lwip 1.3.2 + SafeRTOS

Code attempts to implement TCP server that sits on port 8080.  First connection is fine, data transfer back and forth is fine.  Attempt to call close() causes lwip to hang in netconn_delete.   More specifically in callback on line 458 in tcpip.c

sys_arch_sem_wait(apimsg->msg.conn->op_completed, 0); 

I have tried to set this task priority lower than priority of lwip tasks.... no help....  System exhibits the same behavior on both blocking and non-blocking socket....

code:

static bool CreateConnection()
{
portTickType ulLastTime = xTaskGetTickCount();
int portno;     
 
    _acceptSock = -1;      
    _listenSock = socket(AF_INET, SOCK_STREAM, 0);     
    if (_listenSock < 0)
    {
      error("ERROR opening socket", true);
      return false;
    }
    
    memset((char *) &serv_addr, sizeof(serv_addr), 0);
    portno = 8080;
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = INADDR_ANY;
    serv_addr.sin_port = htons(portno);
    
    // Make the socket non-blocking so we don't stall the task on the accept call
    int NonBlockingFlg = 1;
    lwip_ioctl( _listenSock, FIONBIO, &NonBlockingFlg );    
    
    if (bind(_listenSock, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
    {
      error("ERROR on binding", true);
      return false;
    }
    
    listen(_listenSock, 20);    
    clilen = sizeof(cli_addr);   
 
  return true;
}

static bool AcceptConnection()
{
  _acceptSock = accept(_listenSock, (struct sockaddr *) &cli_addr, &clilen);  
  return _acceptSock > 0;
}

static bool UseConnection()
{
int const IN_BUFFER_SIZE = CHARACTER_ARRAY_0_SIZE/2;
char buffer[IN_BUFFER_SIZE];
int dataLen;
bool retVal = true;
          
  dataLen = recv( _acceptSock, buffer,IN_BUFFER_SIZE - 1, MSG_DONTWAIT);
 
  if(dataLen > 0)
  { // got data
    
    if('x' == buffer[0])
    {
      return false;
    }
    else
    {
      send(_acceptSock, buffer,dataLen,0);
    }
  }
  else
  { // got some error
    int err;
    vPortEnterCritical();
    int retVal = lwip_mike_getlasterror( _acceptSock, &err);
    vPortExitCritical();
 
    if(retVal >= 0)
    {             
      switch(err)
      {
        case EWOULDBLOCK:
        // this is normal - didn't get any data and we have specified non-blocking read
        break;
      
        case ESHUTDOWN:
        // this is disconnect
        /*
        close(_newsockfd);
        _newsockfd = -1;
        close(_sockfd);          
        _sockfd = -1;
        */
        
        retVal = false;
        break;
        
        default:
        {
          char temp[128];
          sprintf(temp,"ERR: %d\r\n", err);
          mi_dbg::DOUT(mi_dbg::DBG_ENET,temp);
        }
        break;
      }
    }
  }
 
  return retVal;
}


typedef enum
{
  ENET_Create
  ,ENET_Accept
  ,ENET_Talk
  ,ENET_Disconnect
  ,ENET_Last
} EnetState_t;

EnetState_t _enetState = ENET_Create;

static void SocketTaskRx(void *pvParameters)
{
    while(1)
    {
      portTickType ulLastTime = xTaskGetTickCount();  
      
      switch(_enetState)
      {
      case  ENET_Create:
        if(lwip_init_done)
        {
          if(CreateConnection())
          {
            mi_dbg::DOUT(mi_dbg::DBG_ENET,"Looking for connection\r\n");
            _enetState =  ENET_Accept;   
          }
        }
        break;
                
      case  ENET_Accept:
          if(AcceptConnection())
          {
             mi_dbg::DOUT(mi_dbg::DBG_ENET,"Connection Accepted\r\n");
             _enetState =  ENET_Talk;     
          }
        break;
        
      case  ENET_Talk:
        if(!UseConnection())
        {
          _enetState =  ENET_Disconnect;     
        }
        break;
        
      case  ENET_Disconnect:
        mi_dbg::DOUT(mi_dbg::DBG_ENET,"Closing conneciton\r\n");
        close(_listenSock);
        close(_acceptSock);
        _enetState =  ENET_Accept;   
        break;
        
      default:
        ASSERT(0);
        break;
      }
      
      xTaskDelayUntil(&ulLastTime, 10);
    }
}

lwip hangs
Report Abuse
  • Reply
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
All Replies
  • efe
    Posted by efe
    on Aug 10 2012 20:31 PM
    Prodigy120 points

    hey did you ever get to the bottom of this issue i am having the sample problem with the exact same configuration. 

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
TI E2E™ Community
  • Support Forums
  • Blogs
  • Videos
  • Groups
  • Site Support & Feedback
  • Settings
TI E2E™ Community Groups
  • TI University Program
  • Make the Switch
  • Microcontroller Projects
  • Motor Drive & Control
Other Communities
  • Deyisupport
  • Designsomething.org
  • beagleboard.org
  • TI on Element 14
  • TI on TechXchangeSM
Other Technical & Support Resources
  • WEBENCH® Design Center
  • Product Information Centers
  • Technical Documents
  • TI Design Network
  • TI Technical Articles
  • TI Training

All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
embedded processors, along with software, tools and the industry’s largest sales/support staff.

© Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy Policy | Terms of Use