/** * Build a pong message. * * @return a /PO message. */ pmsg_t * g2_build_pong(void) { ONCE_FLAG_RUN(build_po_done, g2_build_pong_once); return pmsg_clone(build_po); }
/** * Build an alive ping message. * * @return a /PI message. */ pmsg_t * g2_build_alive_ping(void) { ONCE_FLAG_RUN(build_alive_pi_done, g2_build_alive_ping_once); return pmsg_clone(build_alive_pi); }
/** * Dechunk more data from the input buffer `mb'. * @returns dechunked data in a new buffer, or NULL if no more data. */ static pmsg_t * dechunk_data(rxdrv_t *rx, pmsg_t *mb) { struct attr *attr = rx->opaque; const char *error_str, *src; size_t size; /* * Prepare call to parse_chunk(). */ size = pmsg_size(mb); src = pmsg_read_base(mb); while (size > 0) { size_t ret; g_assert(CHUNK_STATE_ERROR != attr->state); /* * Copy avoidance: if the data we got fits into the current chunk size, * then we don't have to parse anything: all the data belong to the * current chunk, so we can simply pass them to the upper layer. */ if (CHUNK_STATE_DATA == attr->state) { pmsg_t *nmb; nmb = pmsg_clone(mb); if (size < attr->data_remain) { /* The complete chunk data is forwarded to the upper layer */ mb->m_rptr += size; attr->data_remain -= size; } else { /* Only the first ``data_remain'' bytes are forwarded */ mb->m_rptr += attr->data_remain; nmb->m_wptr = deconstify_pointer(&nmb->m_rptr[attr->data_remain]); attr->data_remain = 0; attr->state = CHUNK_STATE_DATA_CRLF; } if (GNET_PROPERTY(rx_debug) > 9) g_debug("dechunk_data: returning chunk of %u bytes", pmsg_size(nmb)); return nmb; } g_assert(size > 0); g_assert(CHUNK_STATE_DATA != attr->state); /* * Parse chunk headers */ ret = parse_chunk(rx, src, size, &error_str); if (0 == ret) { /* * We can't continue if we meet a dechunking error. Signal * our user so that the connection is terminated. */ errno = EIO; attr->cb->chunk_error(rx->owner, "dechunk() failed: %s", error_str); g_warning("dechunk_data(): %s", error_str); break; } g_assert(ret <= size); size -= ret; mb->m_rptr += ret; /* Read that far */ } return NULL; /* No more data */ }