- int ret;
- char tmpbuf[UDP_RECV_CHUNK_SIZE];
- uint16_t data_len;
- char *data_buf;
- size_t packet_size;
- struct udp_audio_header uah;
-
- if (rn->output_error && *rn->output_error < 0) {
- t->error = *rn->output_error;
- return;
- }
- if (!FD_ISSET(purd->fd, &s->rfds))
- return;
- ret = recv_bin_buffer(purd->fd, tmpbuf, UDP_RECV_CHUNK_SIZE);
- if (ret < 0) {
- if (is_errno(ret, EINTR) || is_errno(ret, EAGAIN))
- goto success;
- t->error = ret;
- return;
- }
- t->error = -E_RECV_EOF;
- if (!ret)
- return;
- packet_size = ret;
- for (;;) {
- uint16_t num;
-
- if (!purd->need_more) {
- ret = read_udp_audio_header(tmpbuf, packet_size, &uah);
- if (ret >= 0)
- break;
- goto success; /* drop data */
- }
- num = PARA_MIN(purd->need_more, (uint16_t)packet_size);
- assert(num > 0);
- t->error = add_rn_output(rn, tmpbuf, num);
- if (t->error < 0)
- return;
- purd->need_more -= num;
- if (packet_size <= num)
- goto success;
- packet_size -= num;
- memmove(tmpbuf, tmpbuf + num, packet_size);
+ struct btr_node *btrn = rn->btrn;
+ size_t num_bytes;
+ struct iovec iov[2];
+ int ret, readv_ret, iovcnt;
+
+ t->error = 0;
+ ret = btr_node_status(btrn, 0, BTR_NT_ROOT);
+ if (ret <= 0)
+ goto out;
+ iovcnt = btr_pool_get_buffers(purd->btrp, iov);
+ ret = -E_UDP_OVERRUN;
+ if (iovcnt == 0)
+ goto out;
+ ret = readv_nonblock(purd->fd, iov, iovcnt, &s->rfds, &num_bytes);
+ if (num_bytes == 0)
+ goto out;
+ readv_ret = ret;
+ ret = udp_check_eof(num_bytes, iov);
+ if (ret < 0)
+ goto out;
+ if (iov[0].iov_len >= num_bytes)
+ btr_add_output_pool(purd->btrp, num_bytes, btrn);
+ else { /* both buffers contain data */
+ btr_add_output_pool(purd->btrp, iov[0].iov_len, btrn);
+ btr_add_output_pool(purd->btrp, num_bytes - iov[0].iov_len,
+ btrn);