}
-/**
- * Function called to notify a client about the socket
- * being ready to queue more data. "buf" will be
- * NULL and "size" zero if the socket was closed for
- * writing in the meantime.
- *
- * @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
- */
-static size_t
-transmit_callback (void *cls, size_t size, void *buf)
-{
- struct TransmitCallbackContext *tcc = cls;
- size_t msize;
-
- tcc->th = NULL;
- GNUNET_CONTAINER_DLL_remove (tcc_head, tcc_tail, tcc);
- msize = ntohs (tcc->msg->size);
- if (size == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Transmission to client failed!\n"));
- GNUNET_free (tcc->msg);
- GNUNET_free (tcc);
- return 0;
- }
- GNUNET_assert (size >= msize);
- GNUNET_memcpy (buf, tcc->msg, msize);
- GNUNET_free (tcc->msg);
- GNUNET_free (tcc);
- for (tcc = tcc_head; tcc; tcc = tcc->next)
- {
- if (NULL == tcc->th)
- {
- tcc->th = GNUNET_SERVER_notify_transmit_ready (tcc->client,
- ntohs (tcc->msg->size),
- GNUNET_TIME_UNIT_FOREVER_REL,
- &transmit_callback, tcc);
- break;
- }
- }
- return msize;
-}
-
-
-/**
- * Transmit the given message to the client.
- *
- * @param client target of the message
- * @param msg message to transmit, will be freed!
- */
-static void
-transmit (struct GNUNET_SERVICE_Client *client,
- struct GNUNET_MessageHeader *msg)
-{
- struct GNUNET_MQ_Handle *mq = GNUNET_SERVICE_client_get_mq (client);
- struct GNUNET_MQ_Envelope *env;
-
- /* NOTE: small hack here, should have constructed and
- passed an 'env' in the first place... */
- env = GNUNET_MQ_msg_copy (msg);
- GNUNET_MQ_send (mq,
- env);
-}
-
-
#define MarshallPtr(ptr, base, type) \
if (ptr) \
ptr = (type *) ((char *) ptr - (char *) base)
struct request *rq = cls;
int i, j, csanum;
struct GNUNET_W32RESOLVER_GetMessage *msg;
+ struct GNUNET_MQ_Envelope *msg_env;
struct GNUNET_MessageHeader *msgend;
+ struct GNUNET_MQ_Envelope *msgend_env;
WSAQUERYSETW *qs;
size_t size;
size_t size_recalc;
if (0 == rd_count)
{
- msg = GNUNET_new (struct GNUNET_MessageHeader);
- msg->header.size = htons (sizeof (struct GNUNET_MessageHeader));
- msg->header.type = htons (GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE);
- transmit (rq->client,
- &msg->header);
+ msgend_env = GNUNET_MQ_msg (msgend, GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (rq->client),
+ msgend_env);
GNUNET_CONTAINER_DLL_remove (rq_head,
rq_tail,
rq);
size += blobsize;
}
size_recalc = sizeof (struct GNUNET_W32RESOLVER_GetMessage) + sizeof (WSAQUERYSETW);
- msg = GNUNET_malloc (size);
- msg->header.size = htons (size - sizeof (struct GNUNET_MessageHeader));
- msg->header.type = htons (GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE);
+ msg_env = GNUNET_MQ_msg_extra (msg,
+ size - sizeof (struct GNUNET_MessageHeader),
+ GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE);
msg->af = htonl (rq->af);
msg->sc_data1 = htonl (rq->sc.Data1);
msg->sc_data2 = htons (rq->sc.Data2);
}
he->h_addr_list[j] = NULL;
}
- msgend = GNUNET_new (struct GNUNET_MessageHeader);
-
- msgend->type = htons (GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE);
- msgend->size = htons (sizeof (struct GNUNET_MessageHeader));
+ msgend_env = GNUNET_MQ_msg (msgend, GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE);
if ((char *) ptr - (char *) msg != size || size_recalc != size || size_recalc != ((char *) ptr - (char *) msg))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Error in WSAQUERYSETW size calc: expected %lu, got %lu (recalc %lu)\n",
+ "Error in WSAQUERYSETW size calc: expected %u, got %lu (recalc %u)\n",
size,
(unsigned long) ((char *) ptr - (char *) msg),
size_recalc);
}
MarshallWSAQUERYSETW (qs, &rq->sc);
- transmit (rq->client,
- &msg->header);
- transmit (rq->client,
- msgend);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (rq->client),
+ msg_env);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (rq->client),
+ msgend_env);
GNUNET_CONTAINER_DLL_remove (rq_head,
rq_tail,
rq);
else
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Unknown GUID: %08X-%04X-%04X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n",
+ "Unknown GUID: %08lX-%04X-%04X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n",
sc.Data1,
sc.Data2,
sc.Data3,
for (int i = 0; i < 8; i++)
sc.Data4[i] = msg->sc_data4[i];
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got GUID: %08X-%04X-%04X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n",
+ "Got GUID: %08lX-%04X-%04X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n",
sc.Data1,
sc.Data2,
sc.Data3,