summaryrefslogtreecommitdiff
path: root/pflocal/sock.c
diff options
context:
space:
mode:
Diffstat (limited to 'pflocal/sock.c')
-rw-r--r--pflocal/sock.c58
1 files changed, 26 insertions, 32 deletions
diff --git a/pflocal/sock.c b/pflocal/sock.c
index 350c7de8..292e4290 100644
--- a/pflocal/sock.c
+++ b/pflocal/sock.c
@@ -1,8 +1,7 @@
/* Sock functions
- Copyright (C) 1995, 1996 Free Software Foundation, Inc.
-
- Written by Miles Bader <miles@gnu.ai.mit.edu>
+ Copyright (C) 1995,96,2000,01,02, 2005 Free Software Foundation, Inc.
+ 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
@@ -18,7 +17,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-#include <string.h> /* For bzero() */
+#include <string.h> /* For memset() */
#include <cthreads.h>
@@ -26,6 +25,7 @@
#include "sock.h"
#include "sserver.h"
+#include "connq.h"
/* ---------------------------------------------------------------- */
@@ -94,7 +94,7 @@ sock_acquire_write_pipe (struct sock *sock, struct pipe **pipe)
/* Return a new socket with the given pipe class in SOCK. */
error_t
-sock_create (struct pipe_class *pipe_class, struct sock **sock)
+sock_create (struct pipe_class *pipe_class, mode_t mode, struct sock **sock)
{
error_t err;
struct sock *new = malloc (sizeof (struct sock));
@@ -116,12 +116,13 @@ sock_create (struct pipe_class *pipe_class, struct sock **sock)
new->refs = 0;
new->flags = 0;
new->write_pipe = NULL;
+ new->mode = mode;
new->id = MACH_PORT_NULL;
new->listen_queue = NULL;
new->connect_queue = NULL;
new->pipe_class = pipe_class;
new->addr = NULL;
- bzero (&new->change_time, sizeof (new->change_time));
+ memset (&new->change_time, 0, sizeof (new->change_time));
mutex_init (&new->lock);
*sock = new;
@@ -135,6 +136,8 @@ sock_free (struct sock *sock)
sock_shutdown (sock, SOCK_SHUTDOWN_READ | SOCK_SHUTDOWN_WRITE);
if (sock->id != MACH_PORT_NULL)
mach_port_destroy (mach_task_self (), sock->id);
+ if (sock->listen_queue)
+ connq_destroy (sock->listen_queue);
free (sock);
}
@@ -155,7 +158,7 @@ _sock_norefs (struct sock *sock)
error_t
sock_clone (struct sock *template, struct sock **sock)
{
- error_t err = sock_create (template->pipe_class, sock);
+ error_t err = sock_create (template->pipe_class, template->mode, sock);
if (err)
return err;
@@ -444,6 +447,8 @@ void
sock_shutdown (struct sock *sock, unsigned flags)
{
unsigned old_flags;
+ struct pipe *read_pipe = NULL;
+ struct pipe *write_pipe = NULL;
mutex_lock (&sock->lock);
@@ -451,36 +456,25 @@ sock_shutdown (struct sock *sock, unsigned flags)
sock->flags |= flags;
if (flags & SOCK_SHUTDOWN_READ && !(old_flags & SOCK_SHUTDOWN_READ))
- /* Shutdown the read half. */
{
- struct pipe *pipe = sock->read_pipe;
- if (pipe != NULL)
- {
- sock->read_pipe = NULL;
- /* Unlock SOCK here, as we may subsequently wake up other threads. */
- mutex_unlock (&sock->lock);
- pipe_remove_reader (pipe);
- }
- else
- mutex_unlock (&sock->lock);
+ /* Shutdown the read half. */
+ read_pipe = sock->read_pipe;
+ sock->read_pipe = NULL;
}
-
if (flags & SOCK_SHUTDOWN_WRITE && !(old_flags & SOCK_SHUTDOWN_WRITE))
- /* Shutdown the write half. */
{
- struct pipe *pipe = sock->write_pipe;
- if (pipe != NULL)
- {
- sock->write_pipe = NULL;
- /* Unlock SOCK here, as we may subsequently wake up other threads. */
- mutex_unlock (&sock->lock);
- pipe_remove_writer (pipe);
- }
- else
- mutex_unlock (&sock->lock);
+ /* Shutdown the write half. */
+ write_pipe = sock->write_pipe;
+ sock->write_pipe = NULL;
}
- else
- mutex_unlock (&sock->lock);
+
+ /* Unlock SOCK here, as we may subsequently wake up other threads. */
+ mutex_unlock (&sock->lock);
+
+ if (read_pipe)
+ pipe_remove_reader (read_pipe);
+ if (write_pipe)
+ pipe_remove_writer (write_pipe);
}
/* ---------------------------------------------------------------- */