Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mongoose
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ganil-acq
GANILinux
linux-service
library
mongoose
Commits
f05733da
Commit
f05733da
authored
9 years ago
by
Marko Mikulicic
Browse files
Options
Downloads
Patches
Plain Diff
Fix COAP example, reduce number of ctx switches
PUBLISHED_FROM=7010fff404826c3dfc783d2cbdcbd0936a8a2b85
parent
3c53909e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/coap_client/coap_client.c
+9
-10
9 additions, 10 deletions
examples/coap_client/coap_client.c
examples/coap_server/coap_server.c
+9
-10
9 additions, 10 deletions
examples/coap_server/coap_server.c
with
18 additions
and
20 deletions
examples/coap_client/coap_client.c
+
9
−
10
View file @
f05733da
...
@@ -2,14 +2,14 @@
...
@@ -2,14 +2,14 @@
* Copyright (c) 2015 Cesanta Software Limited
* Copyright (c) 2015 Cesanta Software Limited
* All rights reserved
* All rights reserved
*
*
* This program sends CoAP CON-message to server (coap.me by default)
* This program sends CoAP CON-message to server (coap.me by default)
* and waits for answer.
* and waits for answer.
*/
*/
#include
"mongoose.h"
#include
"mongoose.h"
static
int
s_time_to_exit
=
0
;
static
int
s_time_to_exit
=
0
;
static
char
*
s_default_address
=
"udp://coap.me:5683"
;
static
char
*
s_default_address
=
"udp://coap.me:5683"
;
static
void
coap_handler
(
struct
mg_connection
*
nc
,
int
ev
,
void
*
p
)
{
static
void
coap_handler
(
struct
mg_connection
*
nc
,
int
ev
,
void
*
p
)
{
switch
(
ev
)
{
switch
(
ev
)
{
...
@@ -31,17 +31,16 @@ static void coap_handler(struct mg_connection *nc, int ev, void *p) {
...
@@ -31,17 +31,16 @@ static void coap_handler(struct mg_connection *nc, int ev, void *p) {
break
;
break
;
}
}
case
MG_EV_COAP_ACK
:
case
MG_EV_COAP_ACK
:
case
MG_EV_COAP_RST
:
{
case
MG_EV_COAP_RST
:
{
struct
mg_coap_message
*
cm
=
(
struct
mg_coap_message
*
)
p
;
struct
mg_coap_message
*
cm
=
(
struct
mg_coap_message
*
)
p
;
printf
(
"ACK/RST for message with msg_id = %d received
\n
"
,
printf
(
"ACK/RST for message with msg_id = %d received
\n
"
,
cm
->
msg_id
);
cm
->
msg_id
);
s_time_to_exit
=
1
;
s_time_to_exit
=
1
;
break
;
break
;
}
}
}
}
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
struct
mg_mgr
mgr
;
struct
mg_mgr
mgr
;
struct
mg_connection
*
nc
;
struct
mg_connection
*
nc
;
char
*
address
=
s_default_address
;
char
*
address
=
s_default_address
;
...
@@ -50,7 +49,7 @@ int main(int argc, char* argv[]) {
...
@@ -50,7 +49,7 @@ int main(int argc, char* argv[]) {
address
=
argv
[
1
];
address
=
argv
[
1
];
}
}
printf
(
"Using %s as CoAP server
\n
"
,
address
);
printf
(
"Using %s as CoAP server
\n
"
,
address
);
mg_mgr_init
(
&
mgr
,
0
);
mg_mgr_init
(
&
mgr
,
0
);
...
@@ -63,10 +62,10 @@ int main(int argc, char* argv[]) {
...
@@ -63,10 +62,10 @@ int main(int argc, char* argv[]) {
mg_set_protocol_coap
(
nc
);
mg_set_protocol_coap
(
nc
);
while
(
!
s_time_to_exit
)
{
while
(
!
s_time_to_exit
)
{
mg_mgr_poll
(
&
mgr
,
1
);
mg_mgr_poll
(
&
mgr
,
1
000000
);
}
}
mg_mgr_free
(
&
mgr
);
mg_mgr_free
(
&
mgr
);
return
0
;
return
0
;
}
}
This diff is collapsed.
Click to expand it.
examples/coap_server/coap_server.c
+
9
−
10
View file @
f05733da
...
@@ -2,18 +2,18 @@
...
@@ -2,18 +2,18 @@
* Copyright (c) 2015 Cesanta Software Limited
* Copyright (c) 2015 Cesanta Software Limited
* All rights reserved
* All rights reserved
*
*
* This program listens on 5683 for CoAP messages,
* This program listens on 5683 for CoAP messages,
* sends ACK is nessesary and dump everything received.
* sends ACK is nessesary and dump everything received.
* It is possible to use ../coap_client to send message.
* It is possible to use ../coap_client to send message.
*/
*/
#include
"mongoose.h"
#include
"mongoose.h"
static
char
*
s_default_address
=
"udp://:5683"
;
static
char
*
s_default_address
=
"udp://:5683"
;
static
int
s_sig_received
=
0
;
static
int
s_sig_received
=
0
;
static
void
signal_handler
(
int
sig_num
)
{
static
void
signal_handler
(
int
sig_num
)
{
signal
(
sig_num
,
signal_handler
);
signal
(
sig_num
,
signal_handler
);
s_sig_received
=
sig_num
;
s_sig_received
=
sig_num
;
}
}
...
@@ -21,7 +21,7 @@ static void coap_handler(struct mg_connection *nc, int ev, void *p) {
...
@@ -21,7 +21,7 @@ static void coap_handler(struct mg_connection *nc, int ev, void *p) {
switch
(
ev
)
{
switch
(
ev
)
{
case
MG_EV_COAP_CON
:
{
case
MG_EV_COAP_CON
:
{
uint32_t
res
;
uint32_t
res
;
struct
mg_coap_message
*
cm
=
(
struct
mg_coap_message
*
)
p
;
struct
mg_coap_message
*
cm
=
(
struct
mg_coap_message
*
)
p
;
printf
(
"CON with msg_id = %d received
\n
"
,
cm
->
msg_id
);
printf
(
"CON with msg_id = %d received
\n
"
,
cm
->
msg_id
);
res
=
mg_coap_send_ack
(
nc
,
cm
->
msg_id
);
res
=
mg_coap_send_ack
(
nc
,
cm
->
msg_id
);
if
(
res
==
0
)
{
if
(
res
==
0
)
{
...
@@ -34,10 +34,9 @@ static void coap_handler(struct mg_connection *nc, int ev, void *p) {
...
@@ -34,10 +34,9 @@ static void coap_handler(struct mg_connection *nc, int ev, void *p) {
}
}
case
MG_EV_COAP_NOC
:
case
MG_EV_COAP_NOC
:
case
MG_EV_COAP_ACK
:
case
MG_EV_COAP_ACK
:
case
MG_EV_COAP_RST
:
{
case
MG_EV_COAP_RST
:
{
struct
mg_coap_message
*
cm
=
(
struct
mg_coap_message
*
)
p
;
struct
mg_coap_message
*
cm
=
(
struct
mg_coap_message
*
)
p
;
printf
(
"ACK/RST/NOC with msg_id = %d received
\n
"
,
printf
(
"ACK/RST/NOC with msg_id = %d received
\n
"
,
cm
->
msg_id
);
cm
->
msg_id
);
break
;
break
;
}
}
}
}
...
@@ -58,12 +57,12 @@ int main() {
...
@@ -58,12 +57,12 @@ int main() {
return
-
1
;
return
-
1
;
}
}
printf
(
"Listening for CoAP messages at %s
\n
"
,
s_default_address
);
printf
(
"Listening for CoAP messages at %s
\n
"
,
s_default_address
);
mg_set_protocol_coap
(
nc
);
mg_set_protocol_coap
(
nc
);
while
(
!
s_sig_received
)
{
while
(
!
s_sig_received
)
{
mg_mgr_poll
(
&
mgr
,
1
);
mg_mgr_poll
(
&
mgr
,
1
000000
);
}
}
printf
(
"Exiting on signal %d
\n
"
,
s_sig_received
);
printf
(
"Exiting on signal %d
\n
"
,
s_sig_received
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment