Documentation ¶
Overview ¶
Package tcpopt implements encoding and decoding of TCP-level socket options.
Index ¶
- func Register(level, name int, fn func([]byte) (Option, error))
- func Unregister(level, name int)
- type Cork
- type ECN
- type Error
- type KeepAlive
- type KeepAliveIdleInterval
- type KeepAliveProbeCount
- type KeepAliveProbeInterval
- type MSS
- type NoDelay
- type NotSentLowWMK
- type Option
- type ReceiveBuffer
- type SendBuffer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cork ¶
type Cork bool
Cork specifies the use of TCP_CORK or TCP_NOPUSH option.
On DragonFly BSD, the caller may need to adjust the net.inet.tcp.disable_nopush kernel state. NetBSD and Windows don't support this option.
type ECN ¶
type ECN bool
ECN specifies the use of ECN.
Only Darwin supports this option.
type Error ¶
type Error int
Error represents an error on the socket.
type KeepAlive ¶
type KeepAlive bool
KeepAlive specifies the use of keep alive.
type KeepAliveIdleInterval ¶
KeepAliveIdleInterval is the idle interval until the first probe is sent.
OpenBSD doesn't support this option. See TCP_KEEPIDLE or TCP_KEEPALIVE for further information.
func (KeepAliveIdleInterval) Level ¶
func (ka KeepAliveIdleInterval) Level() int
Level implements the Level method of Option interface.
func (KeepAliveIdleInterval) Marshal ¶
func (ka KeepAliveIdleInterval) Marshal() ([]byte, error)
Marshal implements the Marshal method of Option interface.
func (KeepAliveIdleInterval) Name ¶
func (ka KeepAliveIdleInterval) Name() int
Name implements the Name method of Option interface.
type KeepAliveProbeCount ¶
type KeepAliveProbeCount int
KeepAliveProbeCount is the number of keepalive probes should be repeated when the peer is not responding.
OpenBSD and Windows don't support this option. See TCP_KEEPCNT for further information.
func (KeepAliveProbeCount) Level ¶
func (ka KeepAliveProbeCount) Level() int
Level implements the Level method of Option interface.
func (KeepAliveProbeCount) Marshal ¶
func (ka KeepAliveProbeCount) Marshal() ([]byte, error)
Marshal implements the Marshal method of Option interface.
func (KeepAliveProbeCount) Name ¶
func (ka KeepAliveProbeCount) Name() int
Name implements the Name method of Option interface.
type KeepAliveProbeInterval ¶
KeepAliveProbeInterval is the interval between keepalive probes.
OpenBSD doesn't support this option. See TCP_KEEPINTVL for further information.
func (KeepAliveProbeInterval) Level ¶
func (ka KeepAliveProbeInterval) Level() int
Level implements the Level method of Option interface.
func (KeepAliveProbeInterval) Marshal ¶
func (ka KeepAliveProbeInterval) Marshal() ([]byte, error)
Marshal implements the Marshal method of Option interface.
func (KeepAliveProbeInterval) Name ¶
func (ka KeepAliveProbeInterval) Name() int
Name implements the Name method of Option interface.
type MSS ¶
type MSS int
MSS specifies the maximum segment size.
type NoDelay ¶
type NoDelay bool
NoDelay specifies the use of Nagle's algorithm.
type NotSentLowWMK ¶
type NotSentLowWMK int
NotSentLowWMK specifies the amount of unsent bytes in transmission queue. The network poller such as kqueue or epoll doesn't report that the connection is writable while the amount of unsent data size is greater than NotSentLowWMK.
Only Darwin and Linux support this option. See TCP_NOTSENT_LOWAT for further information.
func (NotSentLowWMK) Level ¶
func (ns NotSentLowWMK) Level() int
Level implements the Level method of Option interface.
func (NotSentLowWMK) Marshal ¶
func (ns NotSentLowWMK) Marshal() ([]byte, error)
Marshal implements the Marshal method of Option interface.
func (NotSentLowWMK) Name ¶
func (ns NotSentLowWMK) Name() int
Name implements the Name method of Option interface.
type Option ¶
type Option interface { // Level returns the platform-specific socket option level. Level() int // Name returns the platform-specific socket option name. Name() int // Marshal returns the binary encoding of socket option. Marshal() ([]byte, error) }
An Option represents a socket option.
Example ¶
package main import ( "log" "net" "time" "github.com/mikioh/tcp" "github.com/mikioh/tcpopt" ) func main() { c, err := net.Dial("tcp", "golang.org:80") if err != nil { log.Fatal(err) } defer c.Close() tc, err := tcp.NewConn(c) if err != nil { log.Fatal(err) } if err := tc.SetOption(tcpopt.KeepAlive(true)); err != nil { log.Fatal(err) } if err := tc.SetOption(tcpopt.KeepAliveIdleInterval(3 * time.Minute)); err != nil { log.Fatal(err) } if err := tc.SetOption(tcpopt.KeepAliveProbeInterval(30 * time.Second)); err != nil { log.Fatal(err) } if err := tc.SetOption(tcpopt.KeepAliveProbeCount(3)); err != nil { log.Fatal(err) } }
Output:
type ReceiveBuffer ¶
type ReceiveBuffer int
ReceiveBuffer specifies the size of receive buffer.
func (ReceiveBuffer) Level ¶
func (rb ReceiveBuffer) Level() int
Level implements the Level method of Option interface.
func (ReceiveBuffer) Marshal ¶
func (rb ReceiveBuffer) Marshal() ([]byte, error)
Marshal implements the Marshal method of Option interface.
func (ReceiveBuffer) Name ¶
func (rb ReceiveBuffer) Name() int
Name implements the Name method of Option interface.
type SendBuffer ¶
type SendBuffer int
SendBuffer specifies the size of send buffer.
func (SendBuffer) Level ¶
func (sb SendBuffer) Level() int
Level implements the Level method of Option interface.
func (SendBuffer) Marshal ¶
func (sb SendBuffer) Marshal() ([]byte, error)
Marshal implements the Marshal method of Option interface.
func (SendBuffer) Name ¶
func (sb SendBuffer) Name() int
Name implements the Name method of Option interface.