net/gcoap: add macro to delay initialization of gcoap#12798
net/gcoap: add macro to delay initialization of gcoap#12798leandrolanzieri merged 1 commit intoRIOT-OS:masterfrom
Conversation
|
Thanks for the thumbs up, @pokgak. Unfortunately, I can't add you as a reviewer (yet), but I know this PR is important for gcoap support of DTLS. If you'd like to review it, I bet we could talk @leandrolanzieri or @miri64 into giving a proxy-ACK. ;-) |
pokgak
left a comment
There was a problem hiding this comment.
This is definitely simpler than the lazy init approach. I like how, with CFLAG, you can document what the flag does compared to pseudomodules where there is normally no documentation about it.
How can this CFLAG be included as a dependency to another module? I haven't seen any CFLAGS in Makefile.dep so not sure if there are any rules regarding CFLAGS in that file or not.
leandrolanzieri
left a comment
There was a problem hiding this comment.
I certainly find this solution simpler than lazy init mode.
Although, I wonder if we should add some inline function to check if the server is already running or not. I think, for example, about the gcoap_cli, when you call coap info it will tell you that the server is listening on GCOAP_PORT even when gcoap is not initialized yet. There may be in the future some other modules that depend on gcoap server to be running on init?
Otherwise I find this macro to be a good solution, and agree with @miri64 's proposal for the renaming.
|
@pokgak, would a function like Also, we may create some more generic facility on the state of gcoap, which I kind of started with |
|
Comments addressed. |
leandrolanzieri
left a comment
There was a problem hiding this comment.
Changes look good. I tested this and works as expected. ACK.
|
@kb2ma please squash |
1b0f9cb to
e873e58
Compare
|
Squashed and tests pass. |
Contribution description
Sometimes we do not wish gcoap to start at auto-initialization time. For example, #12104 must initialize its credman tool for DTLS before the gcoap thread starts. We wish to facilitate this use case without breaking existing applications. This PR adds a macro,
GCOAP_INIT_DELAY, to accomplish this goal. When set to 1, gcoap must be started explicitly.Testing procedure
In the gcoap example
main(), insert the snippet below before the call togcoap_cli_init().Test with and without defining the macro at compile time with something like:
When defined, you should see the following at startup, and be able to send/receive gcoap messages as usual.
Issues/PRs references
Alternative to #12529.