In lwip/api/sockets.c, “set_errno(err)” probably not running properly

arespno
Posts: 9
Joined: Sat Feb 20, 2016 12:19 pm

In lwip/api/sockets.c, “set_errno(err)” probably not running properly

Postby arespno » Mon Nov 06, 2017 4:01 am

In components/lwip/api/sockets.c, line 437:

Code: Select all


#if LWIP_SOCKET_SET_ERRNO
#ifndef set_errno
#define set_errno(err) do { if (err) { errno = (err); } } while(0)
#endif
#else /* LWIP_SOCKET_SET_ERRNO */
#define set_errno(err)
#endif /* LWIP_SOCKET_SET_ERRNO */

When "err" is 0, “set_errno(err)” probably not running properly.
So the value of "errno" is still the last value.
For example in components/lwip/api/sockets.c, line 1504:

Code: Select all


  if (i == -1) {
    LWIP_DEBUGF(SOCKETS_DEBUG, ("-1 / ENFILE (could not allocate socket)\n"));
    netconn_delete(conn);
    set_errno(ENFILE);
    return -1;
  }
  conn->socket = i;
  LWIP_DEBUGF(SOCKETS_DEBUG, ("%d\n", i));
  set_errno(0);
  return i;


User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: In lwip/api/sockets.c, “set_errno(err)” probably not running properly

Postby kolban » Mon Nov 06, 2017 5:24 am

I have always believed that one should check errno when the call last made indicates an error as opposed to using errno as a test for an error.

For example:

int rc = foo();
if (rc == -1) {
printf("error from foo was %d\n", errno);
}
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Who is online

Users browsing this forum: No registered users and 64 guests