From 980e2112cf7a987df40b3157a417ad0e3a831476 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Fri, 27 Apr 2012 15:32:39 +0200 Subject: Add MSG_PEEK support to pflocal * libpipe/pq.h (packet_peek): Declare new function. * libpipe/pq.c (packet_read): Move code to new `packet_fetch' function, call it with `remove' set to 1. (packet_fetch): New function with code from `packet_read', but do not remove data if `remove' is 0. (packet_peek): New function, calls `packet_fetch' with `remove' set to 0. * libpipe/dgram.c (dgram_read): When MSG_PEEK is in *flags, do not dequeue and only peek data. * libpipe/seqpack.c (seqpack_read): Likewise. * libpipe/stream.c (stream_read): Likewise. * pflocal/socket.c (S_socket_recv): Pass MSG_PEEK flag to libpipe. --- libpipe/seqpack.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'libpipe/seqpack.c') diff --git a/libpipe/seqpack.c b/libpipe/seqpack.c index 44a15a03..041abb74 100644 --- a/libpipe/seqpack.c +++ b/libpipe/seqpack.c @@ -43,8 +43,17 @@ static error_t seqpack_read (struct packet *packet, int *dequeue, unsigned *flags, char **data, size_t *data_len, size_t amount) { - error_t err = packet_read (packet, data, data_len, amount); - *dequeue = (packet_readable (packet) == 0); + error_t err; + if (flags && *flags & MSG_PEEK) + { + err = packet_peek (packet, data, data_len, amount); + *dequeue = 0; + } + else + { + err = packet_read (packet, data, data_len, amount); + *dequeue = (packet_readable (packet) == 0); + } return err; } -- cgit v1.2.3