From dc095770749d83d948f8bd294226c79a91f30256 Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Mon, 31 Jul 1995 20:01:27 +0000 Subject: (pipe_recv): Assert that a control packet should only have a source address if there is no corresponding data packet. (pipe_send): Change the test to determine whether we should write a control packet, so that we only do so if we need to. Also, don't record the source address in control packets, as it's recorded in the following data packet anyway, and this prevents it from being dealloc'd twice. --- libpipe/pipe.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'libpipe/pipe.c') diff --git a/libpipe/pipe.c b/libpipe/pipe.c index 73463acd..d0035cbb 100644 --- a/libpipe/pipe.c +++ b/libpipe/pipe.c @@ -19,6 +19,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include /* For bzero() */ +#include #include #include @@ -114,11 +115,16 @@ pipe_send (struct pipe *pipe, void *source, if (pipe->flags & PIPE_BROKEN) return EPIPE; - if (control || ports) + if (control_len > 0 || num_ports > 0) /* Write a control packet. */ { + /* Note that we don't record the source address in control packets, as + it's recorded in the following data packet anyway, and this prevents + it from being dealloc'd twice; this depends on the fact that we + always write a data packet. */ struct packet *control_packet = - pq_queue (pipe->queue, PACKET_TYPE_CONTROL, source); + pq_queue (pipe->queue, PACKET_TYPE_CONTROL, NULL); + if (control_packet == NULL) err = ENOBUFS; else @@ -206,13 +212,19 @@ pipe_recv (struct pipe *pipe, int noblock, unsigned *flags, void **source, packet_read_ports (packet, ports, num_ports); packet_read_source (packet, &control_source); + packet = pq_next (pq, PACKET_TYPE_DATA, control_source); - if (!packet && source) - /* Since there is no data, say where the control data came from. */ - *source = control_source; - else if (control_source) - /* Otherwise be sure to get rid of our reference to the address. */ - pipe_dealloc_addr (control_source); + + /* Control packets should only have a source address if they're not + followed by a data packet. */ + assert (!!packet == !control_source); + + if (!packet) + if (source) + /* Since there is no data, say where the control data came from. */ + *source = control_source; + else + pipe_dealloc_addr (control_source); } else /* No control data... */ -- cgit v1.2.3