From 8e660447410117edd49f41f7aa758e49254ae2d5 Mon Sep 17 00:00:00 2001 From: Nayana Bidari Date: Tue, 26 Jan 2021 18:02:53 -0800 Subject: Initialize the send buffer handler in endpoint creation. - This CL will initialize the function handler used for getting the send buffer size limits during endpoint creation and does not require the caller of SetSendBufferSize(..) to know the endpoint type(tcp/udp/..) PiperOrigin-RevId: 353992634 --- pkg/tcpip/socketops.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'pkg/tcpip/socketops.go') diff --git a/pkg/tcpip/socketops.go b/pkg/tcpip/socketops.go index 4149b91da..7eabbc599 100644 --- a/pkg/tcpip/socketops.go +++ b/pkg/tcpip/socketops.go @@ -205,6 +205,11 @@ type SocketOptions struct { // bindToDevice determines the device to which the socket is bound. bindToDevice int32 + // getSendBufferLimits provides the handler to get the min, default and + // max size for send buffer. It is initialized at the creation time and + // will not change. + getSendBufferLimits GetSendBufferLimits `state:"manual"` + // sendBufferSize determines the send buffer size for this socket. sendBufferSize int64 @@ -218,9 +223,10 @@ type SocketOptions struct { // InitHandler initializes the handler. This must be called before using the // socket options utility. -func (so *SocketOptions) InitHandler(handler SocketOptionsHandler, stack StackHandler) { +func (so *SocketOptions) InitHandler(handler SocketOptionsHandler, stack StackHandler, getSendBufferLimits GetSendBufferLimits) { so.handler = handler so.stackHandler = stack + so.getSendBufferLimits = getSendBufferLimits } func storeAtomicBool(addr *uint32, v bool) { @@ -568,14 +574,17 @@ func (so *SocketOptions) GetSendBufferSize() (int64, *Error) { // SetSendBufferSize sets value for SO_SNDBUF option. notify indicates if the // stack handler should be invoked to set the send buffer size. -func (so *SocketOptions) SetSendBufferSize(sendBufferSize int64, notify bool, getBufferLimits GetSendBufferLimits) { - v := sendBufferSize - ss := getBufferLimits(so.stackHandler) +func (so *SocketOptions) SetSendBufferSize(sendBufferSize int64, notify bool) { + if so.handler.IsUnixSocket() { + return + } + v := sendBufferSize if notify { // TODO(b/176170271): Notify waiters after size has grown. // Make sure the send buffer size is within the min and max // allowed. + ss := so.getSendBufferLimits(so.stackHandler) min := int64(ss.Min) max := int64(ss.Max) // Validate the send buffer size with min and max values. -- cgit v1.2.3