-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
POSIX sockets + lwIP: bad file descriptor #11212
Comments
I'll have a look at this in the next few days. |
Sorry for the delay... :-( I'm not really understanding what the problem is here. You say on Is the problem that the error numbers have different values on different platforms? Since those are provided by the libc we don't have any influence on that. I recommend to use the defines to identify them. |
Hi Martine. Yes, you're right that the description is unclear. What I meant is that I get the same results on samr21-xpro and iotlab-m3 BEFORE performing the following change (i think it's a bug) diff --git a/sys/posix/sockets/posix_sockets.c b/sys/posix/sockets/posix_sockets.c
index ae7195b32..8c7f16708 100644
--- a/sys/posix/sockets/posix_sockets.c
+++ b/sys/posix/sockets/posix_sockets.c
@@ -222,6 +222,7 @@ static int _sockaddr_to_ep(const struct sockaddr *address, socklen_t address_len
}
struct sockaddr_in *in_addr = (struct sockaddr_in *)address;
out->family = AF_INET;
+ out->netif = SOCK_ADDR_ANY_NETIF;
out->addr.ipv4_u32 = in_addr->sin_addr.s_addr;
out->port = ntohs(in_addr->sin_port);
break;
@@ -233,6 +234,7 @@ static int _sockaddr_to_ep(const struct sockaddr *address, socklen_t address_len
}
struct sockaddr_in6 *in6_addr = (struct sockaddr_in6 *)address;
out->family = AF_INET6;
+ out->netif = SOCK_ADDR_ANY_NETIF;
memcpy(&out->addr.ipv6, &in6_addr->sin6_addr, sizeof(out->addr.ipv6));
out->port = ntohs(in6_addr->sin6_port);
break; AFTER the change, I get a different error: "Bad file descriptor" on iotlab-m3 and native, and "hardfault" on samr21-xpro. |
Ah. Indeed this is a bug and should be fixed. I'll try to find out, why the |
22 is EINVAL in newlib btw |
The stack is to small for all the IP stacked on IP. If I patch your Makefile diff --git a/src/Makefile b/src/Makefile
index e36691b..2784a3a 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -59,6 +59,7 @@ endif
CFLAGS += -DSO_REUSE
CFLAGS += -DLWIP_SO_RCVTIMEO
+CFLAGS += -DTHREAD_STACKSIZE_MAIN="(2*THREAD_STACKSIZE_DEFAULT)"
#CFLAGS += -DLWIP_SOCK_TCP_ACCEPT_TIMEOUT=500
#CFLAGS += -DPOSIX_SETSOCKOPT I get a bad file descriptor for |
For the |
So, now for the question, why As you may have noticed, that RIOT/sys/posix/sockets/posix_sockets.c Line 346 in f6ee0ac
For write it basically just wraps around RIOT/sys/posix/sockets/posix_sockets.c Lines 314 to 326 in f6ee0ac
edit: somehow github excepted this comment too early, will continue in separate comment |
Appearently the flags for this check Lines 325 to 328 in f6ee0ac
are not set accordingly. |
That's great, thanks for your help. I don't think I could've solved it myself. I'll patch the Makefile and wait for the PRs to be merged. Thanks again! |
#11575 still needs to be merged for this issue to be considered fixed |
#11575 was merged. |
Description
I've been testing the POSIX TCP/IP implementation in RIOT and I've come up with a few problems for the same code depending on the platform.
For testing I've created a simple echo server/client combining the posix sockets example and the LWIP TCP example. I tested the code on linux and it runs without issue (see the branch echo-v2-linux).
Steps to reproduce the issue
Testing the code on different platforms I get the following
I figured that the error 22 was the result of a an uninitialized netif on the call to _sockaddr_to_ep inside
_bind_connect
leading to a NULL return in _netif_to_bind_addrHowever if y change the following code
I get the "Bad file number" message on iotlab-m3 and a hard fault on samr21-xpro.
Am I missing something obvious? I still don't have such a good grasp of the lwip API to see what is wrong with the code.
Expected results
Similar to the result on echo-v2-linux
Actual results
Bad file descriptor on iotlab-m3 and native, and hardfault on samr21-xpro.
Versions
The text was updated successfully, but these errors were encountered: