/** * Function called to notify a client about the connection * begin ready to queue more data. @a buf will be * NULL and @a size zero if the connection was closed for * writing in the meantime. * * @param cls closure * @param size number of bytes available in @a buf * @param buf where the callee should write the message * @return number of bytes written to @a buf */ static size_t core_mq_ntr (void *cls, size_t size, void *buf) { struct GNUNET_MQ_Handle *mq = cls; struct CoreMQState *mqs = GNUNET_MQ_impl_state (mq); const struct GNUNET_MessageHeader *mh = GNUNET_MQ_impl_current (mq); size_t msg_size = ntohs (mh->size); LOG (GNUNET_ERROR_TYPE_DEBUG, "ntr called (size %u, type %u)\n", msg_size, ntohs (mh->type)); mqs->th = NULL; if (NULL == buf) { LOG (GNUNET_ERROR_TYPE_DEBUG, "send error\n"); GNUNET_MQ_inject_error (mq, GNUNET_MQ_ERROR_WRITE); return 0; } memcpy (buf, mh, msg_size); GNUNET_MQ_impl_send_continue (mq); return msg_size; }
/** * Transmit a queued message to the session's client. * * @param cls consensus session * @param size number of bytes available in buf * @param buf where the callee should write the message * @return number of bytes written to buf */ static size_t transmit_queued (void *cls, size_t size, void *buf) { struct GNUNET_MQ_Handle *mq = cls; struct ServerClientSocketState *state = GNUNET_MQ_impl_state (mq); const struct GNUNET_MessageHeader *msg = GNUNET_MQ_impl_current (mq); size_t msg_size; GNUNET_assert (NULL != buf); msg_size = ntohs (msg->size); GNUNET_assert (size >= msg_size); memcpy (buf, msg, msg_size); state->th = NULL; GNUNET_MQ_impl_send_continue (mq); return msg_size; }
/** * Transmit a queued message to the session's client. * * @param cls consensus session * @param size number of bytes available in @a buf * @param buf where the callee should write the message * @return number of bytes written to buf */ static size_t connection_client_transmit_queued (void *cls, size_t size, void *buf) { struct GNUNET_MQ_Handle *mq = cls; const struct GNUNET_MessageHeader *msg; struct ClientConnectionState *state = mq->impl_state; size_t msg_size; GNUNET_assert (NULL != mq); msg = GNUNET_MQ_impl_current (mq); if (NULL == buf) { GNUNET_MQ_inject_error (mq, GNUNET_MQ_ERROR_READ); return 0; } if ( (GNUNET_YES == state->receive_requested) && (GNUNET_NO == state->receive_active) ) { state->receive_active = GNUNET_YES; GNUNET_CLIENT_receive (state->connection, handle_client_message, mq, GNUNET_TIME_UNIT_FOREVER_REL); } msg_size = ntohs (msg->size); GNUNET_assert (size >= msg_size); memcpy (buf, msg, msg_size); state->th = NULL; GNUNET_MQ_impl_send_continue (mq); return msg_size; }