tcpopt

package module
v0.0.0-...-172688c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2019 License: BSD-2-Clause Imports: 6 Imported by: 7

README

Package tcpopt implements encoding and decoding of TCP-level socket options.

GoDoc Build Status Build status Go Report Card

Documentation

Overview

Package tcpopt implements encoding and decoding of TCP-level socket options.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(level, name int, fn func([]byte) (Option, error))

Register registers a socket option parser.

func Unregister

func Unregister(level, name int)

Unregister unregisters a socket option parser.

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.

func (Cork) Level

func (ck Cork) Level() int

Level implements the Level method of Option interface.

func (Cork) Marshal

func (ck Cork) Marshal() ([]byte, error)

Marshal implements the Marshal method of Option interface.

func (Cork) Name

func (ck Cork) Name() int

Name implements the Name method of Option interface.

type ECN

type ECN bool

ECN specifies the use of ECN.

Only Darwin supports this option.

func (ECN) Level

func (cn ECN) Level() int

Level implements the Level method of Option interface.

func (ECN) Marshal

func (cn ECN) Marshal() ([]byte, error)

Marshal implements the Marshal method of Option interface.

func (ECN) Name

func (cn ECN) Name() int

Name implements the Name method of Option interface.

type Error

type Error int

Error represents an error on the socket.

func (Error) Level

func (e Error) Level() int

Level implements the Level method of Option interface.

func (Error) Marshal

func (e Error) Marshal() ([]byte, error)

Marshal implements the Marshal method of Option interface.

func (Error) Name

func (e Error) Name() int

Name implements the Name method of Option interface.

type KeepAlive

type KeepAlive bool

KeepAlive specifies the use of keep alive.

func (KeepAlive) Level

func (ka KeepAlive) Level() int

Level implements the Level method of Option interface.

func (KeepAlive) Marshal

func (ka KeepAlive) Marshal() ([]byte, error)

Marshal implements the Marshal method of Option interface.

func (KeepAlive) Name

func (ka KeepAlive) Name() int

Name implements the Name method of Option interface.

type KeepAliveIdleInterval

type KeepAliveIdleInterval time.Duration

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

type KeepAliveProbeInterval time.Duration

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.

func (MSS) Level

func (mss MSS) Level() int

Level implements the Level method of Option interface.

func (MSS) Marshal

func (mss MSS) Marshal() ([]byte, error)

Marshal implements the Marshal method of Option interface.

func (MSS) Name

func (mss MSS) Name() int

Name implements the Name method of Option interface.

type NoDelay

type NoDelay bool

NoDelay specifies the use of Nagle's algorithm.

func (NoDelay) Level

func (nd NoDelay) Level() int

Level implements the Level method of Option interface.

func (NoDelay) Marshal

func (nd NoDelay) Marshal() ([]byte, error)

Marshal implements the Marshal method of Option interface.

func (NoDelay) Name

func (nd NoDelay) Name() int

Name implements the Name method of Option interface.

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:

func Parse

func Parse(level, name int, b []byte) (Option, error)

Parse parses a socket option.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL