summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2020-07-05 17:09:58 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2020-07-05 17:09:58 +0200
commit9b64495c6cd22cd65f118c18a36b2de7cbde4344 (patch)
tree4ea487ab78ca73da32c50fa48bc3be546213551f
parent414f6c35a62a7e72f40c39089a9952913a7eeb90 (diff)
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.
-rw-r--r--pflocal/sock.c5
-rw-r--r--pflocal/sock.h3
-rw-r--r--pflocal/socket.c12
3 files changed, 13 insertions, 7 deletions
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. */
diff --git a/pflocal/sock.h b/pflocal/sock.h
index dca16755..c1e73f9b 100644
--- a/pflocal/sock.h
+++ b/pflocal/sock.h
@@ -52,6 +52,9 @@ struct sock
another socket. */
struct pipe *read_pipe, *write_pipe;
+ /* The write limit that this side would like write_pipe to support. */
+ size_t req_write_limit;
+
/* FLAGS from SOCK_*, below. */
unsigned flags;
diff --git a/pflocal/socket.c b/pflocal/socket.c
index 8f90da2d..89444370 100644
--- a/pflocal/socket.c
+++ b/pflocal/socket.c
@@ -479,12 +479,10 @@ S_socket_getopt (struct sock_user *user,
break;
}
pipe = sock->write_pipe;
- if (!pipe)
- {
- ret = ENOTCONN;
- break;
- }
- *(int *)*value = pipe->write_limit;
+ if (pipe)
+ *(int *)*value = pipe->write_limit;
+ else
+ *(int *)*value = sock->req_write_limit;
*value_len = sizeof (int);
break;
case SO_ERROR:
@@ -594,7 +592,7 @@ S_socket_setopt (struct sock_user *user,
pipe = sock->write_pipe;
if (!pipe)
{
- ret = ENOTCONN;
+ sock->req_write_limit = new;
break;
}