[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-devel] [bug #35928] BSD sockets functions must set errno for POSIX
From: |
Mason |
Subject: |
[lwip-devel] [bug #35928] BSD sockets functions must set errno for POSIX-compliance |
Date: |
Wed, 21 Mar 2012 09:39:05 +0000 |
User-agent: |
Mozilla/5.0 (Windows NT 5.1; rv:10.0.2) Gecko/20120216 Firefox/10.0.2 SeaMonkey/2.7.2 |
URL:
<http://savannah.nongnu.org/bugs/?35928>
Summary: BSD sockets functions must set errno for
POSIX-compliance
Project: lwIP - A Lightweight TCP/IP stack
Submitted by: mason
Submitted on: Wed 21 Mar 2012 09:39:03 AM GMT
Category: sockets
Severity: 3 - Normal
Item Group: Faulty Behaviour
Status: None
Privacy: Public
Assigned to: None
Open/Closed: Open
Discussion Lock: Any
Planned Release:
lwIP version: 1.4.0
_______________________________________________________
Details:
I am porting libcurl on top of lwip on a (mostly) POSIX-compliant embedded
platform. In this configuration, libcurl expects a POSIX-compliant network
stack. On a closely related note, cf. task #11879: Add POSIX conformant header
files <https://savannah.nongnu.org/task/?11879>.
lwip provides a BSD sockets compatibility layer which, by default, is not
POSIX-compliant, because none of the sockets function set errno.
cf. set_errno and sock_set_errno macros
#ifdef ERRNO
#ifndef set_errno
#define set_errno(err) errno = (err)
#endif
#else /* ERRNO */
#define set_errno(err)
#endif /* ERRNO */
#define sock_set_errno(sk, e) do { \
sk->err = (e); \
set_errno(sk->err); \
} while (0)
Thus, by default, set_errno is a NOP.
(NB: the ERRNO macro is undocumented)
Consider the requirements for connect:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html
Upon successful completion, connect() shall return 0;
otherwise, -1 shall be returned and errno set to indicate the error.
(The same requirement exists for all BSD sockets functions.)
In lwip, the (optional) BSD sockets compatibility layer is compiled
only if LWIP_SOCKET is defined to a non-zero value. If an lwip
integrator needs the sockets layer, it is very likely that he expects
the BSD sockets functions to comply to POSIX.
Thus, if LWIP_SOCKET is defined, I believe the BSD sockets functions
must set errno by default. It might make sense to allow integrators
to disable this feature, but compliance should be the default.
Which means applying the following trivial patch, to remove the
undocumented ERRNO macro.
--- sockets.c 2012-02-23 10:57:12.796875000 +0100
+++ sockets.c 2012-03-20 10:50:40.375000000 +0100
@@ -158,13 +158,9 @@
((unsigned)(-(err)) < ERR_TO_ERRNO_TABLE_SIZE ? \
err_to_errno_table[-(err)] : EIO)
-#ifdef ERRNO
#ifndef set_errno
#define set_errno(err) errno = (err)
#endif
-#else /* ERRNO */
-#define set_errno(err)
-#endif /* ERRNO */
#define sock_set_errno(sk, e) do { \
sk->err = (e); \
An integrator can
#define set_errno(err)
in his port's cc.h if he needs to disable setting errno (why?!)
Please seriously consider this patch, libcurl checks errno all over
the place.
_______________________________________________________
File Attachments:
-------------------------------------------------------
Date: Wed 21 Mar 2012 09:39:03 AM GMT Name: patch_sockets.txt Size: 422B
By: mason
<http://savannah.nongnu.org/bugs/download.php?file_id=25426>
_______________________________________________________
Reply to this item at:
<http://savannah.nongnu.org/bugs/?35928>
_______________________________________________
Message sent via/by Savannah
http://savannah.nongnu.org/
- [lwip-devel] [bug #35928] BSD sockets functions must set errno for POSIX-compliance,
Mason <=
- [lwip-devel] [bug #35928] BSD sockets functions must set errno for POSIX-compliance, Kieran Mansley, 2012/03/21
- [lwip-devel] [bug #35928] BSD sockets functions must set errno for POSIX-compliance, Mason, 2012/03/21
- [lwip-devel] [bug #35928] BSD sockets functions must set errno for POSIX-compliance, Simon Goldschmidt, 2012/03/21
- [lwip-devel] [bug #35928] BSD sockets functions must set errno for POSIX-compliance, Mason, 2012/03/21
- [lwip-devel] [bug #35928] BSD sockets functions must set errno for POSIX-compliance, Mason, 2012/03/21
- [lwip-devel] [bug #35928] BSD sockets functions must set errno for POSIX-compliance, Mason, 2012/03/21
- [lwip-devel] [bug #35928] BSD sockets functions must set errno for POSIX-compliance, Mason, 2012/03/26
- Re: [lwip-devel] [bug #35928] BSD sockets functions must set errno for POSIX-compliance, Mason, 2012/03/27
- [lwip-devel] [bug #35928] BSD sockets functions must set errno for POSIX-compliance, Simon Goldschmidt, 2012/03/27
- [lwip-devel] [bug #35928] BSD sockets functions must set errno for POSIX-compliance, Mason, 2012/03/28