From: ng0 Date: Tue, 5 Sep 2017 12:08:13 +0000 (+0000) Subject: doc: gnunet-c-tutorial: include example 4 and 5. X-Git-Tag: gnunet-0.11.0rc0~128 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=dca832adb5eb0ad336b0baaebf8d826c9b5ed125;p=oweals%2Fgnunet.git doc: gnunet-c-tutorial: include example 4 and 5. --- 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. In GNUnet, messages are always sent beginning with a {\tt struct GNUNET\_MessageHeader} in big endian format. This header defines the size and the type of the message, the payload follows after this header. - -\lstset{language=C} -\begin{lstlisting} -struct GNUNET_MessageHeader -{ - uint16_t size GNUNET_PACKED; - uint16_t type GNUNET_PACKED; -}; +@example +@verbatiminclude tutorial-examples/004.c @end example Existing message types are defined in @file{gnunet\_protocols.h}\\ A common way to create a message is with an envelope: - -\lstset{language=C} -\begin{lstlisting} -struct GNUNET_MQ_Envelope *env; -struct GNUNET_MessageHeader *msg; - -env = GNUNET_MQ_msg_extra (msg, payload_size, GNUNET_MY_MESSAGE_TYPE); -memcpy (&msg[1], &payload, payload_size); -// Send message via message queue 'mq' -GNUNET_mq_send (mq, env); +@example +@verbatiminclude tutorial-examples/005.c @end example 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 @@ +struct GNUNET_MessageHeader +{ + uint16_t size GNUNET_PACKED; + uint16_t type GNUNET_PACKED; +}; 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 @@ +struct GNUNET_MQ_Envelope *env; +struct GNUNET_MessageHeader *msg; + +env = GNUNET_MQ_msg_extra (msg, payload_size, GNUNET_MY_MESSAGE_TYPE); +memcpy (&msg[1], &payload, payload_size); +// Send message via message queue 'mq' +GNUNET_mq_send (mq, env); +