From 9b64495c6cd22cd65f118c18a36b2de7cbde4344 Mon Sep 17 00:00:00 2001
From: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date: Sun, 5 Jul 2020 17:09:58 +0200
Subject: pflocal: support SO_SNDBUF for unconnected sockets

We can store the requested value, to be applied when we connect the
sockets.

* pflocal/sock.h (struct sock): Add req_write_limit field.
* pflocal/sock.c (sock_create): Initialize req_write_limit field to 0.
(sock_connect): Bump the write_limit of the write pipe to the
req_write_limit value.
(sock_shutdown): Update req_write_limit from the write_limit of the
write pipe.
* pflocal/socket.c (S_socket_getopt, S_socket_setopt): When write_pipe
is NULL, use req_write_limit.
---
 pflocal/sock.c | 5 +++++
 1 file changed, 5 insertions(+)

(limited to 'pflocal/sock.c')

diff --git a/pflocal/sock.c b/pflocal/sock.c
index be64a3da..89ba16e2 100644
--- a/pflocal/sock.c
+++ b/pflocal/sock.c
@@ -116,6 +116,7 @@ sock_create (struct pipe_class *pipe_class, mode_t mode, struct sock **sock)
   new->refs = 0;
   new->flags = 0;
   new->write_pipe = NULL;
+  new->req_write_limit = 0;
   new->mode = mode;
   new->id = MACH_PORT_NULL;
   new->listen_queue = NULL;
@@ -397,6 +398,8 @@ sock_connect (struct sock *sock1, struct sock *sock2)
 	  assert_backtrace (pipe);	/* Since PFLOCAL_SOCK_SHUTDOWN_READ isn't set.  */
 	  pipe_add_writer (pipe);
 	  wr->write_pipe = pipe;
+	  if (pipe->write_limit < wr->req_write_limit)
+	    pipe->write_limit = wr->req_write_limit;
 	}
     }
 
@@ -474,6 +477,8 @@ sock_shutdown (struct sock *sock, unsigned flags)
       /* Shutdown the write half.  */
       write_pipe = sock->write_pipe;
       sock->write_pipe = NULL;
+      if (write_pipe)
+	sock->req_write_limit = write_pipe->write_limit;
     }
 
   /* Unlock SOCK here, as we may subsequently wake up other threads. */
-- 
cgit v1.2.3