1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
// Copyright (c) 2015-2024 MinIO, Inc.
//
// This file is part of MinIO Object Storage stack
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package net
import (
"syscall"
"time"
)
// A TCPConfig structure is used to configure
// a TCP client or server connections.
type TCPConfig struct {
// IdleTimeout is the maximum time duration for idle connections
// before they are forcibly closed.
IdleTimeout time.Duration
// UserTimeout is the maximum amount of time that transmitted
// data may remain unacknowledged before forcefully closing the
// connection.
//
// Moreover, when used with TCP keepalives, UserTimeout
// overrides keepalive to determine when to close a connection
// due to keepalive failure.
//
// If empty, no TCP user timeout is set.
UserTimeout time.Duration
// SendBufSize sets a custom send buffer size on the TCP socket if
// not zero.
SendBufSize int
// RecvBufSize, sets a custom receive buffer size on the TCP socket if
// not zero.
RecvBufSize int
// If true, sets TCP_NODELAY on the network connection which
// disables Nagle's algorithm such that small packages are not
// combined into larger ones but sent right away.
NoDelay bool
// If non-empty, create a TCP socket on the given virtual routing
// and forwarding (VRF) interface.
Interface string
// Trace is a callback for debug logging
Trace func(string)
}
// Control applies the TCPConfig to a raw network connection before dialing.
//
// Network and address parameters passed to Control function are not
// necessarily the ones passed to Dial. For example, passing "tcp" to Dial
// will cause the Control function to be called with "tcp4" or "tcp6".
func (c *TCPConfig) Control(network, address string, rc syscall.RawConn) error {
if c == nil {
return nil
}
return c.control(network, address, rc)
}
// Clone returns a copy of a TCPConfig structure.
func (c *TCPConfig) Clone() *TCPConfig {
if c == nil {
return nil
}
return &TCPConfig{
IdleTimeout: c.IdleTimeout,
UserTimeout: c.UserTimeout,
SendBufSize: c.SendBufSize,
RecvBufSize: c.RecvBufSize,
NoDelay: c.NoDelay,
Interface: c.Interface,
Trace: c.Trace,
}
}
|