From 0406fa6f2e3b6014f465c4d987759324065375df Mon Sep 17 00:00:00 2001 From: ng0 Date: Tue, 5 Sep 2017 12:10:12 +0000 Subject: doc: gnunet-c-tutorial: example 6. --- doc/gnunet-c-tutorial.texi | 36 ++---------------------------------- doc/tutorial-examples/006.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 34 deletions(-) create mode 100644 doc/tutorial-examples/006.c diff --git a/doc/gnunet-c-tutorial.texi b/doc/gnunet-c-tutorial.texi index a08888845..6b2c770f3 100644 --- a/doc/gnunet-c-tutorial.texi +++ b/doc/gnunet-c-tutorial.texi @@ -693,40 +693,8 @@ to actually process the message. Fixed size messages are fully checked by the MQ-logic, and thus only need to provide the handler to process the message. Note that the prefixes {\tt check\_} and {\tt handle\_} are mandatory. - -\lstset{language=c} -\begin{lstlisting} -static void -handle_fix (void *cls, const struct MyMessage *msg) -{ - // process 'msg' -} - -static int -check_var (void *cls, const struct MyVarMessage *msg) -{ - // check 'msg' is well-formed - return GNUNET_OK; -} - -static void -handle_var (void *cls, const struct MyVarMessage *msg) -{ - // process 'msg' -} - -struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_fixed_size (fix, - GNUNET_MESSAGE_TYPE_MY_FIX, - struct MyMessage, - NULL), - GNUNET_MQ_hd_fixed_size (var, - GNUNET_MESSAGE_TYPE_MY_VAR, - struct MyVarMessage, - NULL), - - GNUNET_MQ_handler_end () -}; +@example +@verbatiminclude tutorial-examples/006.c @end example Exercise: Expand your helper function to receive a response message diff --git a/doc/tutorial-examples/006.c b/doc/tutorial-examples/006.c new file mode 100644 index 000000000..944d2b18c --- /dev/null +++ b/doc/tutorial-examples/006.c @@ -0,0 +1,31 @@ +static void +handle_fix (void *cls, const struct MyMessage *msg) +{ + // process 'msg' +} + +static int +check_var (void *cls, const struct MyVarMessage *msg) +{ + // check 'msg' is well-formed + return GNUNET_OK; +} + +static void +handle_var (void *cls, const struct MyVarMessage *msg) +{ + // process 'msg' +} + +struct GNUNET_MQ_MessageHandler handlers[] = { + GNUNET_MQ_hd_fixed_size (fix, + GNUNET_MESSAGE_TYPE_MY_FIX, + struct MyMessage, + NULL), + GNUNET_MQ_hd_fixed_size (var, + GNUNET_MESSAGE_TYPE_MY_VAR, + struct MyVarMessage, + NULL), + + GNUNET_MQ_handler_end () +}; -- cgit v1.2.3