buglwIP - A Lightweight TCP/IP stack - Bugs: bug #48416, Problem with nonblocking connect

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #48416: Problem with nonblocking connect

Submitter:  Christian Prochaska <cproc>
Submitted:  Tue 05 Jul 2016 06:29:25 PM UTC
   
 
Category:  sockets/netconn Severity:  3 - Normal
Item Group:  None Status:  Works For Me
Privacy:  Public Assigned to:  goldsimon
Open/Closed:  Closed Planned Release:  None
lwIP version:  git head

Wed 06 Jul 2016 05:18:18 AM UTC, comment #1: 

This should work: when LWIP_ERROR is correctly defined to execute "handler", tcp_connect() returns ERR_ISCONN. It does raise an error message by default unless LWIP_NOASSERT is defined to help you finding bugs in your application during development.

If you can't get your application to not behave like this, you can change the LWIP_ERROR define to only execute "handler".

Simon Goldschmidt <goldsimon>
Group administrator
Tue 05 Jul 2016 06:29:25 PM UTC, original submission:  

I'm actually not using the most recent version, but from looking at the source code the problem I'm having seems to still exist on the current git master branch (4b136d631af0650247ab1bb21c7eb761d12960b6)

In 'lwip_netconn_do_connect()':

    ...

    case NETCONN_TCP:
      /* Prevent connect while doing any other action. */
      if (msg->conn->state == NETCONN_CONNECT) {
        msg->err = ERR_ALREADY;
      } else if (msg->conn->state != NETCONN_NONE) {
        msg->err = ERR_ISCONN;
      } else {
        setup_tcp(msg->conn);
        msg->err = tcp_connect(msg->conn->pcb.tcp, API_EXPR_REF(msg->msg.bc.ipaddr),
          msg->msg.bc.port, lwip_netconn_do_connected);
        if (msg->err == ERR_OK) {
          u8_t non_blocking = netconn_is_nonblocking(msg->conn);
          msg->conn->state = NETCONN_CONNECT;

    ...

The problem occurred when the function was called for the second time when the connection was already established. I would have expected an 'ERR_ISCONN' status code, but instead tcp_connect() got called for a second time and printed a 'tcp_connect: can only connect from state CLOSED' error message (the actual state was ESTABLISHED).

The reason for the repeated call of 'tcp_connect()' was that 'msg->conn->state' was NETCONN_NONE, as set in 'lwip_netconn_do_connected()' after the connection was established.

Perhaps a new netconn state 'NETCONN_CONNECTED' would be needed here, but I'm not too familiar with lwip interna to be sure about that.

Christian Prochaska <cproc>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by goldsimon (Posted a comment)
  • -email is unavailable- added by cproc (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-07-06 goldsimon StatusNone Works For Me
        Assigned toNone goldsimon
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-bb6a.
    Corresponding source code