-
Notifications
You must be signed in to change notification settings - Fork 10
Compatibility with lwIP and ESP-IDF #13
base: master
Are you sure you want to change the base?
Conversation
lwIP = Lightweight IP library <http://savannah.nongnu.org/projects/lwip/> ESP-IDF = iOT Development Framework for Espressif's ESP32 chip <https://github.com/espressif/esp-idf> New preprocessor flags for configuration: * NYOCI_LWIP -- define if compiling for lwIP. Will be automatically defined if ESP_PLATFORM is defined (i.e. building for ESP-IDF.) * NYOCI_CAN_POLL -- Indicates the `poll` system call is available and should be used instead of `select`. Defaults to 1 unless building for lwIP; explicitly define it as 0 to force use of `select`. * NYOCI_CAN_SENDMSG -- Indicates the `sendmsg` system call is available and should be used instead of `send`. Defaults to 1 unless building for lwIP; explicitly define it as 0 to force use of `send`. Note: `send` does not support setting the “from” address of the packet.
`==` has higher precedence than `&`, so the expression wasn’t doing what was intended.
I think a better approach would be to create a net platform rather than modifying the posix platform in-place, even if the new platform is based on posix. Maybe call it |
src/libnyoci/nyoci-outbound.c
Outdated
@@ -320,7 +320,7 @@ nyoci_outbound_add_options_up_to_key_( | |||
|
|||
#if NYOCI_CONF_TRANS_ENABLE_OBSERVING | |||
if ( (self->current_transaction != NULL) | |||
&& (self->current_transaction->flags & NYOCI_TRANSACTION_OBSERVE == NYOCI_TRANSACTION_OBSERVE) | |||
&& ((self->current_transaction->flags & NYOCI_TRANSACTION_OBSERVE) == NYOCI_TRANSACTION_OBSERVE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Mind pulling this commit out into it's own pull request?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't claim credit -- GCC found it and warned me (but I can't remember which warning flag it was.)
I'll submit a separate PR when I have a chance.
But that would mean duplicating ~1200 lines of code, which I couldn't bring myself to do (I'm pretty strict about DRY.) Consider also that most of the changes aren't specific to lwIP; they'll add support for any other POSIX-like platform that's missing But it is of course your call. I may just keep my fork, err, forked. In that case, mind if I submit a smaller PR for just the ESP32-specific changes (e.g. to logging?) |
I'll take another look over the changes. If there are other POSIX platforms that your changes help make LibNyoci build on (Solaris? QNX? Minix?), then I'd be inclined to accept it. QNX in particular might benefit from it. But I may end up just going ahead and implementing support for native LWIP. Travis is failing here with these changes:
But let me review this stuff before you spend any significant amount of time trying to address that. |
@@ -79,6 +80,12 @@ | |||
PSTR(__FILE__ ":%d: "fmt"\n"), \ | |||
__LINE__, \ | |||
__VA_ARGS__) | |||
#elif ESP_PLATFORM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like all of the changes in this file, including the errno
stuff. May be worth spinning out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still reviewing, but I like several of your changes so far. There are a few minor style issues (some spaces snuck in where tabs should be, etc), but I won't nit-pick those until I'm sure I grok the whole picture—which I will try to do in the morning.
@@ -34,40 +34,46 @@ | |||
|
|||
#if !VERBOSE_DEBUG | |||
|
|||
#define CSTR(x) (x) | |||
#define CSTR(x) (x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather significant changes in the whitespace not be combined with material additions or changes to a file, unless it is unavoidable. It makes the diffs harder to read.
That aside, I'm having trouble getting my brain to not be weirded out by the use of full indents, though. That's largely why I used single-space indents in assert-macros.h
: indented preprocessor macros look weird to me after 20+ years of not indenting them at all. I found the single-space indentation improved readability for assert-macros.h
without looking too weird to my eyes, but maybe I'm just being stubborn and tabs are really the way to go.
@@ -230,7 +287,7 @@ nyoci_plat_init(nyoci_t self) { | |||
#if NYOCI_PLAT_NET_POSIX_FAMILY == AF_INET6 | |||
if (self->plat.mcfd_v6 == -1) { | |||
self->plat.mcfd_v6 = socket(AF_INET6, SOCK_DGRAM, 0); | |||
check(self->plat.mcfd_v6 >= 0); | |||
check_errno(self->plat.mcfd_v6 >= 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for all of these sorts of changes.
ret = sendmsg(fd, &msg, flags); | ||
|
||
check(ret > 0); | ||
check_string(ret >= 0, strerror(errno)); | ||
#else // !NYOCI_CAN_SENDMSG | ||
abort(); //TODO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a little hard to tell what is going on here from looking at the diff on GitHub. Why is this abort()
here? Would an #error
be more suitable?
} | ||
ret = nyoci_plat_update_fdsets(self, &reads, &writes, &errors, &fdCount, &cms); | ||
if (ret != NYOCI_STATUS_OK) | ||
goto bail; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know there is a lot of old code in LibNyoci that doesn't use braces for single-line if()
statements, but ever since the goto fail bug I require the use of curly braces for all if()
statements in all new code, even if copy-pasted.
Good news: It looks like I'll be adding real native support for LWIP at some point between now and the end of November. I'll also be adding support for bare-bones OpenThread. |
You've got some good changes in this PR, so I'm going to keep this open for now. |
Mostly so that an outgoing packet can be logged by coap_dump_header.
strtol returns an long, not a pointer.
It wasn’t at all obvious how to specify the CoAP URL, without browsing the source code...
Added FETCH/PATCH and status codes from RFC 8132. Changed Internet-Draft references to the RFCs they became.
lwIP = Lightweight IP library
http://savannah.nongnu.org/projects/lwip/
ESP-IDF = iOT Development Framework for Espressif's ESP32 chip
https://github.com/espressif/esp-idf
New preprocessor flags for configuration:
defined if ESP_PLATFORM is defined (i.e. building for ESP-IDF.)
poll
system call is available andshould be used instead of
select
. Defaults to 1 unless buildingfor lwIP; explicitly define it as 0 to force use of
select
.sendmsg
system call isavailable and should be used instead of
send
. Defaults to 1 unlessbuilding for lwIP; explicitly define it as 0 to force use of
send
.Note:
send
does not support setting the “from” address of thepacket.
Fixes #8
(I also added a one-line commit that fixes a recent regression on the master branch
that I discovered when rebasing just now.)