static ssize_t net_chanel_queue_write_to_net(net_chanel_t bc, int fd) { struct net_chanel_queue * chanel; ssize_t send_size; assert(bc); assert(bc->m_type == &s_net_chanel_type_queue); chanel = (struct net_chanel_queue *)bc; if (chanel->m_size == 0) return 0; send_size = cpe_send(fd, chanel->m_buf, chanel->m_size, 0); if (send_size < 0) return send_size; if (send_size != chanel->m_size) { memmove(chanel->m_buf, chanel->m_buf + send_size, chanel->m_size - send_size); chanel->m_size -= send_size; } else { chanel->m_size = 0; } chanel->m_state = net_chanel_queue_calac_state(chanel); return send_size; }
/** Process send queue head, associated with socket/event pfd. * Perform synchronization on the pollfd associated with the queue (disables * POLLOUT if queue is empty). * * @remark Memory management (allocation and deallocation) must be done by * the caller of cpe_send_enqueue(). */ apr_status_t cpe_sender(cpe_network_ctx *nctx) { cpe_io_buf *sendbuf; apr_size_t howmany; apr_status_t rv; cpe_queue_t *head; cpe_log(CPE_DEB, "%s", "enter"); head = nctx->nc_sendQ; if (head->cq_next == NULL) { cpe_log(CPE_DEB, "queue %p (socket %p) is empty, disabling POLLOUT", head, head->cq_pfd->desc.s); rv = cpe_pollset_update(head->cq_pfd, head->cq_pfd->reqevents & ~APR_POLLOUT); assert(rv == APR_SUCCESS); return rv; } sendbuf = head->cq_next; howmany = sendbuf->buf_len; assert(howmany > 0); rv = cpe_send(head->cq_pfd->desc.s, sendbuf, &howmany); /* XXX what to do with rv ? */ head->cq_total_sent += howmany; if (sendbuf->buf_offset == sendbuf->buf_len) { head->cq_nelems--; sendbuf->inqueue = 0; sendbuf->buf_offset = 0; cpe_log(CPE_DEB, "buffer %p (on queue %p, nelems %d, socket %p) completely sent", sendbuf, head, head->cq_nelems, head->cq_pfd->desc.s); /* Update queue to next buffer to send; remove buffer from queue. */ if (sendbuf->next != NULL) { head->cq_next = sendbuf->next; sendbuf->next = NULL; } else { head->cq_next = NULL; } if (sendbuf->destroy) { cpe_log(CPE_DEB, "%s", "iobuf marked to be destroyed"); cpe_iobuf_destroy(&sendbuf, nctx); } } return APR_SUCCESS; }