+/**
+ * Function called to notify a client about the connection
+ * begin ready to queue more data. "buf" will be
+ * NULL and "size" zero if the connection was closed for
+ * writing in the meantime.
+ *
+ * FIXME
+ *
+ * @param cls closure
+ * @param size number of bytes available in buf
+ * @param buf where the callee should write the message
+ * @return number of bytes written to buf
+ */
+size_t
+data_ready (void *cls, size_t size, void *buf)
+{
+ struct GNUNET_MessageHeader *msg;
+ size_t total_size;
+
+ if (NULL == buf || 0 == size)
+ {
+ GNUNET_SCHEDULER_shutdown();
+ return 0;
+ }
+
+ total_size = data_size + sizeof (struct GNUNET_MessageHeader);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending %u bytes\n", data_size);
+ GNUNET_assert (size >= total_size);
+
+ msg = buf;
+ msg->size = htons (total_size);
+ msg->type = htons (GNUNET_MESSAGE_TYPE_MESH_CLI);
+ memcpy (&msg[1], cls, data_size);
+ if (GNUNET_NO == echo)
+ {
+ listen_stdio ();
+ }
+ else
+ {
+ echo_time = GNUNET_TIME_absolute_get ();
+ }
+
+ return total_size;
+}
+
+
+/**
+ * Task run in monitor mode when the user presses CTRL-C to abort.
+ * Stops monitoring activity.
+ *
+ * @param cls Closure (unused).
+ * @param tc scheduler context
+ */
+static void
+read_stdio (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ static char buf[60000];
+
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ {
+ return;
+ }
+
+ data_size = read (0, buf, 60000);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "stdio read %u bytes\n", data_size);
+ if (data_size < 1)
+ {
+ GNUNET_SCHEDULER_shutdown();
+ return;
+ }
+ GNUNET_MESH_notify_transmit_ready (ch, GNUNET_NO,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ data_size
+ + sizeof (struct GNUNET_MessageHeader),
+ &data_ready, buf);
+}
+
+
+/**
+ * Start listening to stdin
+ */
+static void
+listen_stdio (void)
+{
+ struct GNUNET_NETWORK_FDSet *rs;
+
+ rs = GNUNET_NETWORK_fdset_create ();
+ GNUNET_NETWORK_fdset_set_native (rs, 0);
+ GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ rs, NULL,
+ &read_stdio, NULL);
+ GNUNET_NETWORK_fdset_destroy (rs);
+}
+
+