para_fd_set(purd->fd, &s->rfds, &s->max_fileno);
}
+static int udp_check_eof(size_t sz, struct iovec iov[2])
+{
+ if (sz < FEC_EOF_PACKET_LEN)
+ return 0;
+ if (iov[0].iov_len >= FEC_EOF_PACKET_LEN) {
+ if (memcmp(iov[0].iov_base, FEC_EOF_PACKET,
+ FEC_EOF_PACKET_LEN) != 0)
+ return 0;
+ return -E_RECV_EOF;
+ }
+ if (memcmp(iov[0].iov_base, FEC_EOF_PACKET, iov[0].iov_len) != 0)
+ return 0;
+ if (memcmp(iov[1].iov_base, FEC_EOF_PACKET + iov[0].iov_len,
+ FEC_EOF_PACKET_LEN - iov[0].iov_len) != 0)
+ return 0;
+ return -E_RECV_EOF;
+}
+
static void udp_recv_post_select(__a_unused struct sched *s, struct task *t)
{
struct receiver_node *rn = container_of(t, struct receiver_node, task);
struct private_udp_recv_data *purd = rn->private_data;
struct btr_node *btrn = rn->btrn;
- int ret;
- char *buf = NULL;
- size_t packet_size, bufsize;
+ size_t packet_size;
+ struct iovec iov[2];
+ int ret, iovcnt;
t->error = 0;
ret = btr_node_status(btrn, 0, BTR_NT_ROOT);
return;
if (!FD_ISSET(purd->fd, &s->rfds))
return;
- bufsize = btr_pool_get_buffer(purd->btrp, &buf);
+ iovcnt = btr_pool_get_buffers(purd->btrp, iov);
ret = -E_UDP_OVERRUN;
- if (bufsize == 0)
+ if (iovcnt == 0)
goto err;
- ret = recv_bin_buffer(purd->fd, buf, bufsize);
+ ret = para_readv(purd->fd, iov, iovcnt);
if (ret == 0)
ret = -E_RECV_EOF;
if (ret < 0)
goto err;
packet_size = ret;
- if (packet_size >= FEC_EOF_PACKET_LEN) {
- if (!memcmp(buf, FEC_EOF_PACKET, FEC_EOF_PACKET_LEN)) {
- PARA_INFO_LOG("received eof packet\n");
- ret = -E_RECV_EOF;
- goto err;
- }
+ ret = udp_check_eof(packet_size, iov);
+ if (ret < 0)
+ goto err;
+ if (iov[0].iov_len >= packet_size)
+ btr_add_output_pool(purd->btrp, packet_size, btrn);
+ else { /* both buffers contain data */
+ btr_add_output_pool(purd->btrp, iov[0].iov_len, btrn);
+ btr_add_output_pool(purd->btrp, packet_size - iov[0].iov_len,
+ btrn);
}
- btr_add_output_pool(purd->btrp, packet_size, btrn);
return;
err:
btr_remove_node(btrn);