aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorng0 <ng0@infotropique.org>2017-09-05 12:08:13 +0000
committerng0 <ng0@infotropique.org>2017-09-05 12:09:01 +0000
commitdca832adb5eb0ad336b0baaebf8d826c9b5ed125 (patch)
tree57f34e8a7922fabb074cd118e0265b32340a51ae /doc
parentcfba13ba203d18db23ff758ddbb4bc4d42f9c9a7 (diff)
downloadgnunet-dca832adb5eb0ad336b0baaebf8d826c9b5ed125.tar.gz
gnunet-dca832adb5eb0ad336b0baaebf8d826c9b5ed125.zip
doc: gnunet-c-tutorial: include example 4 and 5.
Diffstat (limited to 'doc')
-rw-r--r--doc/gnunet-c-tutorial.texi22
-rw-r--r--doc/tutorial-examples/004.c5
-rw-r--r--doc/tutorial-examples/005.c8
3 files changed, 17 insertions, 18 deletions
diff --git a/doc/gnunet-c-tutorial.texi b/doc/gnunet-c-tutorial.texi
index 2973dd779..a08888845 100644
--- a/doc/gnunet-c-tutorial.texi
+++ b/doc/gnunet-c-tutorial.texi
@@ -657,28 +657,14 @@ there are errors communicating with the service.
657In GNUnet, messages are always sent beginning with a {\tt struct GNUNET\_MessageHeader} 657In GNUnet, messages are always sent beginning with a {\tt struct GNUNET\_MessageHeader}
658in big endian format. This header defines the size and the type of the 658in big endian format. This header defines the size and the type of the
659message, the payload follows after this header. 659message, the payload follows after this header.
660 660@example
661\lstset{language=C} 661@verbatiminclude tutorial-examples/004.c
662\begin{lstlisting}
663struct GNUNET_MessageHeader
664{
665 uint16_t size GNUNET_PACKED;
666 uint16_t type GNUNET_PACKED;
667};
668@end example 662@end example
669 663
670Existing message types are defined in @file{gnunet\_protocols.h}\\ 664Existing message types are defined in @file{gnunet\_protocols.h}\\
671A common way to create a message is with an envelope: 665A common way to create a message is with an envelope:
672 666@example
673\lstset{language=C} 667@verbatiminclude tutorial-examples/005.c
674\begin{lstlisting}
675struct GNUNET_MQ_Envelope *env;
676struct GNUNET_MessageHeader *msg;
677
678env = GNUNET_MQ_msg_extra (msg, payload_size, GNUNET_MY_MESSAGE_TYPE);
679memcpy (&msg[1], &payload, payload_size);
680// Send message via message queue 'mq'
681GNUNET_mq_send (mq, env);
682@end example 668@end example
683 669
684Exercise: Define a message struct that includes a 32-bit 670Exercise: Define a message struct that includes a 32-bit
diff --git a/doc/tutorial-examples/004.c b/doc/tutorial-examples/004.c
new file mode 100644
index 000000000..0ef007907
--- /dev/null
+++ b/doc/tutorial-examples/004.c
@@ -0,0 +1,5 @@
1struct GNUNET_MessageHeader
2{
3 uint16_t size GNUNET_PACKED;
4 uint16_t type GNUNET_PACKED;
5};
diff --git a/doc/tutorial-examples/005.c b/doc/tutorial-examples/005.c
new file mode 100644
index 000000000..0c459f509
--- /dev/null
+++ b/doc/tutorial-examples/005.c
@@ -0,0 +1,8 @@
1struct GNUNET_MQ_Envelope *env;
2struct GNUNET_MessageHeader *msg;
3
4env = GNUNET_MQ_msg_extra (msg, payload_size, GNUNET_MY_MESSAGE_TYPE);
5memcpy (&msg[1], &payload, payload_size);
6// Send message via message queue 'mq'
7GNUNET_mq_send (mq, env);
8