kmgNet

package
v0.0.0-...-05317bf Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2015 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosing = errors.New("use of closed network connection")
View Source
var FakeAddr = fakeAddr{}
View Source
var ProtocolNotSupportPortError = errors.New("Protocol Not Support Port")

Functions

func BufioConn

func BufioConn() net.Conn

func CloseRead

func CloseRead(conn net.Conn) error

func CloseWrite

func CloseWrite(conn net.Conn) error

func GetCurrentAddrListString

func GetCurrentAddrListString() string

获取当前地址的列表的字符串

func GetDefaultGateway

func GetDefaultGateway() string

func IsBadFileDescripter

func IsBadFileDescripter(err error) bool

func IsConnectionRefused

func IsConnectionRefused(err error) bool

icmp 报告服务器不存在,通常是服务器掉进程了. 出现位置 udp write

func IsNetworkIsUnreachable

func IsNetworkIsUnreachable(err error) bool

当前设备没有可用的网络设备,在网络切换时会出现 出现位置 udp read, udp write,udp dial

func IsNoRouteToHost

func IsNoRouteToHost(err error) bool

服务器关机

func IsPrivateNetwork

func IsPrivateNetwork(ip net.IP) bool

func IsResourceBusy

func IsResourceBusy(err error) bool

在创建vpn的tun设备时,该tun设备号被占据的时候出现

func IsSocketCloseError

func IsSocketCloseError(err error) bool

是否是因为socket没有关闭,或者socket根本没有连接而导致的错误,或者被reset (表示这个连接应该被马上关闭) 这个可以用来在监听请求的时候,检测到服务器关闭事件.

func IsTimeoutError

func IsTimeoutError(err error) bool

在网络请求额时候,使用conn.SetDeadLine(xxx) 设置超时时间后,请求确实超过超时时间的报错.

func JoinHostPortInt

func JoinHostPortInt(host string, port int) string

func LessDelayDial

func LessDelayDial(network string, address string) (conn net.Conn, err error)

func LessDelayTcpConn

func LessDelayTcpConn(conn *net.TCPConn) (connOut net.Conn, err error)

func ListenerConnWrapper

func ListenerConnWrapper(l net.Listener, connWrapper ConnWrapper) net.Listener

func MustGetCurrentIpList

func MustGetCurrentIpList() (ipList []net.IP)

返回当前机器上面的所有ip列表.没有ip会报错

func MustGetCurrentIpWithPortList

func MustGetCurrentIpWithPortList(port uint16) (sList []string)

func MustGetFirstIPByNetDeviceName

func MustGetFirstIPByNetDeviceName(devname string) net.IP

返回nil表示没找到这个设备,或者这个设备上面没有ip

func MustGetHostFromAddr

func MustGetHostFromAddr(addr string) string

func MustGetIpFromAddr

func MustGetIpFromAddr(addri net.Addr) (ip net.IP)

无法获取到ip,会panic

func MustGetLocalAddrFromAddr

func MustGetLocalAddrFromAddr(addr net.Addr) string

从一个net.Listener里面读取需要Dial的地址(测试用的比较多)

func MustGetLocalAddrFromListener

func MustGetLocalAddrFromListener(listener net.Listener) string

从一个net.Listener里面读取需要Dial的地址(测试用的比较多)

func MustGetServerAddrString

func MustGetServerAddrString(s Server) string

func MustGetServerLocalAddrString

func MustGetServerLocalAddrString(s Server) string

func MustLessDelayListen

func MustLessDelayListen(network string, address string) net.Listener

func MustListen

func MustListen(network string, address string) net.Listener

func MustParseCIDR

func MustParseCIDR(s string) *net.IPNet

func MustServerStart

func MustServerStart(s Server)

func MustTcpRandomListen

func MustTcpRandomListen() net.Listener

func NewDebugConn

func NewDebugConn(conn net.Conn, name string) net.Conn

func NewDebugConnNoData

func NewDebugConnNoData(conn net.Conn) net.Conn

func NewFixedAddressDialer

func NewFixedAddressDialer(parent Dialer, network string, address string) func() (net.Conn, error)

func NewFixedDialerV2

func NewFixedDialerV2(parent Dialer, network string, address string) func(network, address string) (net.Conn, error)

func NewRwcOverConn

func NewRwcOverConn(rwc io.ReadWriteCloser, conn net.Conn) net.Conn

func NewSizeDebugConn

func NewSizeDebugConn(conn net.Conn, name string) net.Conn

func NewStringDebugConn

func NewStringDebugConn(conn net.Conn, name string) net.Conn

func NewTimeoutDialer

func NewTimeoutDialer(timeout time.Duration) func(network, addr string) (net.Conn, error)

拨号的时候有一个timeout,每次读和写的时候也有一个timeout

func PortFromAddrString

func PortFromAddrString(addr string) (int, error)

func PortFromNetAddr

func PortFromNetAddr(addr net.Addr) (int, error)

func RunTCPServerListenAddr

func RunTCPServerListenAddr(listenAddr string, handle ConnHandlerFunc) (closer func() error)

func RunTCPServerV2

func RunTCPServerV2(Listener net.Listener, handle ConnHandlerFunc) (closer func() error)

func RwcConn

func RwcConn(rwc io.ReadWriteCloser) net.Conn

func SetDnsServerAddr

func SetDnsServerAddr(ip string)

func SizeString

func SizeString(byteNum int64) string

func SizeStringWithPadding

func SizeStringWithPadding(byteNum int64) string

在开头加padding,尝试使长度一致,如果数据超级大有可能会坏掉

func SpeedString

func SpeedString(byteNum int, dur time.Duration) string

func SpeedStringWithFloat

func SpeedStringWithFloat(bytePerSecond float64) string

func TimeoutConn

func TimeoutConn(conn net.Conn, timeout time.Duration) net.Conn

Types

type ConnHandler

type ConnHandler interface {
	ConnHandle(conn net.Conn)
}

type ConnHandlerFunc

type ConnHandlerFunc func(conn net.Conn)

func (ConnHandlerFunc) ConnHandle

func (f ConnHandlerFunc) ConnHandle(conn net.Conn)

type ConnServer

type ConnServer struct {
	Listener net.Listener
	Handler  ConnHandler
	Closer   io.Closer
}

func NewTCPServer

func NewTCPServer(listenAddr string, hander ConnHandler, closer io.Closer) (s *ConnServer, err error)

这一步会开始监听

func (*ConnServer) Addr

func (server *ConnServer) Addr() (net.Addr, error)

func (*ConnServer) Close

func (server *ConnServer) Close() (err error)

func (*ConnServer) Start

func (server *ConnServer) Start() (err error)

start之前已经监听过了

type ConnWrapper

type ConnWrapper func(conn net.Conn) (net.Conn, error)

type DeviceAddr

type DeviceAddr struct {
	IP        net.IP     //地址上面的ip
	IPNet     *net.IPNet //地址上面的子网
	DevString string     //设备名称 eth0 什么的
}

一个网络设备上面的地址

func GetCurrentDeviceAddr

func GetCurrentDeviceAddr() (ipnets []DeviceAddr, err error)

目前仅支持linux

func (DeviceAddr) IpAddrDel

func (a DeviceAddr) IpAddrDel() (err error)

目前仅支持linux

type Dialer

type Dialer func(network, address string) (net.Conn, error)

func NewDebugDialerNoData

func NewDebugDialerNoData(parent Dialer) Dialer

type DirectDialer

type DirectDialer interface {
	DirectDial() (net.Conn, error)
}

type DirectDialerFunc

type DirectDialerFunc func() (net.Conn, error)

func (DirectDialerFunc) Dial

func (f DirectDialerFunc) Dial() (net.Conn, error)

type FixedAddressDialer

type FixedAddressDialer func() (net.Conn, error)

type FuncServer

type FuncServer struct {
	StartFunc func() error
	CloseFunc func() error
	AddrFunc  func() (net.Addr, error)
	ExistAddr net.Addr
}

func (*FuncServer) Addr

func (s *FuncServer) Addr() (net.Addr, error)

监听地址,如果可能请返回net库里面有的Addr,如果还没有开始监听会panic

func (*FuncServer) Close

func (s *FuncServer) Close() error

关闭服务器,通常需要等一段时间(1ms)来等服务器确实关闭了

func (*FuncServer) Start

func (s *FuncServer) Start() error

type GetUnderlyingConner

type GetUnderlyingConner interface {
	GetUnderlyingConn() net.Conn
}

type RwcDialer

type RwcDialer interface {
	RwcDial(addr string) (rwc io.ReadWriteCloser, err error)
}

type RwcDialerFunc

type RwcDialerFunc func(addr string) (rwc io.ReadWriteCloser, err error)

func (RwcDialerFunc) RwcDial

func (f RwcDialerFunc) RwcDial(addr string) (rwc io.ReadWriteCloser, err error)

type RwcOverConn

type RwcOverConn struct {
	io.Reader
	io.Writer
	io.Closer
	net.Conn
}

func (*RwcOverConn) Close

func (c *RwcOverConn) Close() (err error)

func (*RwcOverConn) GetUnderlyingConn

func (c *RwcOverConn) GetUnderlyingConn() net.Conn

func (*RwcOverConn) Read

func (c *RwcOverConn) Read(p []byte) (n int, err error)

func (*RwcOverConn) Write

func (c *RwcOverConn) Write(p []byte) (n int, err error)

type Server

type Server interface {
	//异步开启服务器
	Start() error
	//关闭服务器,通常需要等一段时间(1ms)来等服务器确实关闭了
	Close() error
	//监听地址,如果可能请返回net库里面有的Addr,如果还没有开始监听会panic
	Addr() (net.Addr, error)
}

这个接口只需要 Close就可以了. 删除这个对象的所有引用.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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