netutil

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2016 License: MIT Imports: 5 Imported by: 26

README

GitHub release GoDoc Build Status Go Report Card License

Add-ons for networking

This package overrides a package of the same name .

Features

  • Functions for IPv4 address space.
  • Utilities for TCP keep-alive.
  • Interface to half-close connections.
  • golang.org/x/net/netutil functions.

Usage

Read the documentation.

License

MIT

Documentation

Overview

Package netutil provides a few more network utilities over golang.org/x/net/netutil.

This package overrides netutil namespace since it provides all functions in golang.org/x/net/netutil.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrIPv6 is an error that a function does not support IPv6.
	ErrIPv6 = errors.New("only IPv4 address is supported")
)

Functions

func HostsFunc

func HostsFunc(n *net.IPNet) (func() net.IP, error)

HostsFunc returns a function to generate all IP addresses in a network. The network address and the broadcast address of the network will be excluded.

The returned function will finally generate nil to tell the end.

The network must be an IPv4 network.

func IP4ToInt

func IP4ToInt(ip net.IP) uint32

IP4ToInt returns uint32 value for an IPv4 address. If ip is not an IPv4 address, this returns 0.

func IntToIP4

func IntToIP4(n uint32) net.IP

IntToIP4 does the reverse of IP4ToInt.

func KeepAliveListener

func KeepAliveListener(l net.Listener) net.Listener

KeepAliveListener returns TCPKeepAliveListener if l is a *net.TCPListener. Otherwise, l is returned without change.

func LimitListener

func LimitListener(l net.Listener, n int) net.Listener

LimitListener is the same as https://godoc.org/golang.org/x/net/netutil#LimitListener

func SetKeepAlive

func SetKeepAlive(c net.Conn)

SetKeepAlive enables TCP keep-alive if c is a *net.TCPConn.

Types

type HalfCloser

type HalfCloser interface {
	CloseRead() error
	CloseWrite() error
}

HalfCloser is an interface for connections that can be half-closed. TCPConn and UNIXConn implement this.

type TCPKeepAliveListener

type TCPKeepAliveListener struct {
	*net.TCPListener
}

TCPKeepAliveListener wraps *net.TCPListener.

func (TCPKeepAliveListener) Accept

func (l TCPKeepAliveListener) Accept() (c net.Conn, err error)

Accept returns a TCP keep-alive enabled connection.

Jump to

Keyboard shortcuts

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