- if (list_empty(&hc->packet_queue))
- return 1;
- list_for_each_entry_safe(qp, tmp, &hc->packet_queue, node) {
- ret = write_ok(hc->fd);
- if (ret <= 0)
- return ret? -E_WRITE_OK : 0;
- ret = write(hc->fd, qp->packet, qp->len);
- if (ret < 0)
- return ret;
- if (ret != qp->len) {
- qp->len -= ret;
- memmove(qp->packet, qp->packet + ret, qp->len);
- return 0;
- }
- hc->pq_bytes -= qp->len;
- free(qp->packet);
- list_del(&qp->node);
- free(qp);
- }
- return 1;
-}
-
-static void http_send(__unused struct audio_format *af,
- long unsigned current_chunk,
- __unused long unsigned chunks_sent, const char *buf, size_t len)
-{
- struct http_client *hc, *tmp;
- int ret;
-
- list_for_each_entry_safe(hc, tmp, &clients, node) {
- if (hc->status != HTTP_STREAMING &&
- hc->status != HTTP_READY_TO_STREAM)
- continue;
- if (hc->status == HTTP_READY_TO_STREAM) {
- if (af->get_header_info && current_chunk) {
- /* need to send header */
- int hlen;
- char *buf = af->get_header_info(&hlen);
- if (!buf || hlen <= 0)
- continue; /* header not yet available */
- PARA_INFO_LOG("queueing header: %d\n", hlen);
- if (queue_packet(hc, buf, hlen) < 0)
- continue;
- } else
- PARA_INFO_LOG("%s", "no need to queue header\n");
- hc->status = HTTP_STREAMING;
- }
- ret = send_queued_packets(hc);
- if (ret < 0) {
- http_shutdown_client(hc, "send error");
- continue;
- }
- if (!len)
- continue;
- if (!ret || write_ok(hc->fd) <= 0) {
- PARA_INFO_LOG("fd %d not ready (%lu bytes queued),"
- " trying to queue packet\n", hc->fd,
- hc->pq_bytes);
- queue_packet(hc, buf, len);
- continue;
- }
-// PARA_DEBUG_LOG("sending %d -> %s\n", len, CLIENT_ADDR(hc));
- ret = write(hc->fd, buf, len);
- if (ret < 0) {
- http_shutdown_client(hc, "send error");