aboutsummaryrefslogtreecommitdiff
path: root/pflocal/connq.c
diff options
context:
space:
mode:
Diffstat (limited to 'pflocal/connq.c')
-rw-r--r--pflocal/connq.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/pflocal/connq.c b/pflocal/connq.c
index 5efeb5d2..d4103840 100644
--- a/pflocal/connq.c
+++ b/pflocal/connq.c
@@ -1,8 +1,8 @@
/* Listen queue functions
- Copyright (C) 1995 Free Software Foundation, Inc.
+ Copyright (C) 1995,96,2001 Free Software Foundation, Inc.
- Written by Miles Bader <miles@gnu.ai.mit.edu>
+ Written by Miles Bader <miles@gnu.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -19,6 +19,7 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <cthreads.h>
+#include <assert.h>
#include "connq.h"
@@ -108,6 +109,20 @@ connq_create (struct connq **cq)
*cq = new;
return 0;
}
+
+/* Destroy a queue. */
+void
+connq_destroy (struct connq *cq)
+{
+ /* Everybody in the queue should hold a reference to the socket
+ containing the queue. */
+ assert (cq->length == 0);
+ /* Nevertheless, malloc(0) or realloc(0) might allocate some small
+ space. */
+ if (cq->queue)
+ free (cq->queue);
+ free (cq);
+}
/* ---------------------------------------------------------------- */
@@ -117,14 +132,17 @@ connq_create (struct connq **cq)
to allow the requesting thread to continue. If NOBLOCK is true,
EWOULDBLOCK is returned when there are no immediate connections
available. */
-error_t
+error_t
connq_listen (struct connq *cq, int noblock,
struct connq_request **req, struct sock **sock)
{
mutex_lock (&cq->lock);
if (noblock && cq->head == cq->tail)
- return EWOULDBLOCK;
+ {
+ mutex_unlock (&cq->lock);
+ return EWOULDBLOCK;
+ }
cq->num_listeners++;
@@ -132,7 +150,7 @@ connq_listen (struct connq *cq, int noblock,
if (hurd_condition_wait (&cq->listeners, &cq->lock))
{
cq->num_listeners--;
- mutex_unlock (&cq->lock);
+ mutex_unlock (&cq->lock);
return EINTR;
}
@@ -149,7 +167,7 @@ connq_listen (struct connq *cq, int noblock,
mutex_unlock (&cq->lock);
- return 0;
+ return 0;
}
/* Return the error code ERR to the thread that made the listen request REQ,
@@ -211,6 +229,7 @@ connq_connect (struct connq *cq, int noblock, struct sock *sock)
return err;
}
+#if 0
/* `Compresses' CQ, by removing any NULL entries. CQ should be locked. */
static void
connq_compress (struct connq *cq)
@@ -231,10 +250,11 @@ connq_compress (struct connq *cq)
/* Move back tail to only include what we kept in the queue. */
cq->tail = comp_tail;
}
+#endif
/* Set CQ's queue length to LENGTH. Any sockets already waiting for a
connections that are past the new length will fail with ECONNREFUSED. */
-error_t
+error_t
connq_set_length (struct connq *cq, int length)
{
mutex_lock (&cq->lock);