diff options
author | ng0 <ng0@infotropique.org> | 2017-09-05 12:08:13 +0000 |
---|---|---|
committer | ng0 <ng0@infotropique.org> | 2017-09-05 12:09:01 +0000 |
commit | dca832adb5eb0ad336b0baaebf8d826c9b5ed125 (patch) | |
tree | 57f34e8a7922fabb074cd118e0265b32340a51ae /doc | |
parent | cfba13ba203d18db23ff758ddbb4bc4d42f9c9a7 (diff) | |
download | gnunet-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.texi | 22 | ||||
-rw-r--r-- | doc/tutorial-examples/004.c | 5 | ||||
-rw-r--r-- | doc/tutorial-examples/005.c | 8 |
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. | |||
657 | In GNUnet, messages are always sent beginning with a {\tt struct GNUNET\_MessageHeader} | 657 | In GNUnet, messages are always sent beginning with a {\tt struct GNUNET\_MessageHeader} |
658 | in big endian format. This header defines the size and the type of the | 658 | in big endian format. This header defines the size and the type of the |
659 | message, the payload follows after this header. | 659 | message, the payload follows after this header. |
660 | 660 | @example | |
661 | \lstset{language=C} | 661 | @verbatiminclude tutorial-examples/004.c |
662 | \begin{lstlisting} | ||
663 | struct GNUNET_MessageHeader | ||
664 | { | ||
665 | uint16_t size GNUNET_PACKED; | ||
666 | uint16_t type GNUNET_PACKED; | ||
667 | }; | ||
668 | @end example | 662 | @end example |
669 | 663 | ||
670 | Existing message types are defined in @file{gnunet\_protocols.h}\\ | 664 | Existing message types are defined in @file{gnunet\_protocols.h}\\ |
671 | A common way to create a message is with an envelope: | 665 | A 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} | ||
675 | struct GNUNET_MQ_Envelope *env; | ||
676 | struct GNUNET_MessageHeader *msg; | ||
677 | |||
678 | env = GNUNET_MQ_msg_extra (msg, payload_size, GNUNET_MY_MESSAGE_TYPE); | ||
679 | memcpy (&msg[1], &payload, payload_size); | ||
680 | // Send message via message queue 'mq' | ||
681 | GNUNET_mq_send (mq, env); | ||
682 | @end example | 668 | @end example |
683 | 669 | ||
684 | Exercise: Define a message struct that includes a 32-bit | 670 | Exercise: 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 @@ | |||
1 | struct 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 @@ | |||
1 | struct GNUNET_MQ_Envelope *env; | ||
2 | struct GNUNET_MessageHeader *msg; | ||
3 | |||
4 | env = GNUNET_MQ_msg_extra (msg, payload_size, GNUNET_MY_MESSAGE_TYPE); | ||
5 | memcpy (&msg[1], &payload, payload_size); | ||
6 | // Send message via message queue 'mq' | ||
7 | GNUNET_mq_send (mq, env); | ||
8 | |||