net

package
v0.19.2 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2021 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

package net is intended to provide compatible interfaces with the Go standard library's net package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UseDriver

func UseDriver(driver DeviceDriver)

Types

type Addr

type Addr interface {
	Network() string // name of the network (for example, "tcp", "udp")
	String() string  // string form of address (for example, "192.0.2.1:25", "[2001:db8::1]:80")
}

Addr represents a network end point address.

type Conn

type Conn interface {
	// Read reads data from the connection.
	// Read can be made to time out and return an Error with Timeout() == true
	// after a fixed time limit; see SetDeadline and SetReadDeadline.
	Read(b []byte) (n int, err error)

	// Write writes data to the connection.
	// Write can be made to time out and return an Error with Timeout() == true
	// after a fixed time limit; see SetDeadline and SetWriteDeadline.
	Write(b []byte) (n int, err error)

	// Close closes the connection.
	// Any blocked Read or Write operations will be unblocked and return errors.
	Close() error

	// LocalAddr returns the local network address.
	LocalAddr() Addr

	// RemoteAddr returns the remote network address.
	RemoteAddr() Addr

	// SetDeadline sets the read and write deadlines associated
	// with the connection. It is equivalent to calling both
	// SetReadDeadline and SetWriteDeadline.
	//
	// A deadline is an absolute time after which I/O operations
	// fail with a timeout (see type Error) instead of
	// blocking. The deadline applies to all future and pending
	// I/O, not just the immediately following call to Read or
	// Write. After a deadline has been exceeded, the connection
	// can be refreshed by setting a deadline in the future.
	//
	// An idle timeout can be implemented by repeatedly extending
	// the deadline after successful Read or Write calls.
	//
	// A zero value for t means I/O operations will not time out.
	SetDeadline(t time.Time) error

	// SetReadDeadline sets the deadline for future Read calls
	// and any currently-blocked Read call.
	// A zero value for t means Read will not time out.
	SetReadDeadline(t time.Time) error

	// SetWriteDeadline sets the deadline for future Write calls
	// and any currently-blocked Write call.
	// Even if write times out, it may return n > 0, indicating that
	// some of the data was successfully written.
	// A zero value for t means Write will not time out.
	SetWriteDeadline(t time.Time) error
}

Conn is a generic stream-oriented network connection. This interface is from the Go standard library.

func Dial

func Dial(network, address string) (Conn, error)

Dial connects to the address on the named network. It tries to provide a mostly compatible interface to net.Dial().

type DeviceDriver

type DeviceDriver interface {
	GetDNS(domain string) (string, error)
	ConnectTCPSocket(addr, port string) error
	ConnectSSLSocket(addr, port string) error
	ConnectUDPSocket(addr, sendport, listenport string) error
	DisconnectSocket() error
	StartSocketSend(size int) error
	Write(b []byte) (n int, err error)
	ReadSocket(b []byte) (n int, err error)
	IsSocketDataAvailable() bool

	// FIXME: this is really specific to espat, and maybe shouldn't be part
	// of the driver interface
	Response(timeout int) ([]byte, error)
}
var ActiveDevice DeviceDriver

type IP

type IP []byte

IP is an IP address. Unlike the standard implementation, it is only a buffer of bytes that contains the string form of the IP address, not the full byte format used by the Go standard .

func ParseIP

func ParseIP(s string) IP

ParseIP parses s as an IP address, returning the result.

func (IP) String

func (ip IP) String() string

String returns the string form of the IP address ip.

type SerialConn

type SerialConn struct {
	Adaptor DeviceDriver
}

SerialConn is a loosely net.Conn compatible implementation

func (*SerialConn) Close

func (c *SerialConn) Close() error

Close closes the connection. Currently only supports a single Read or Write operations without blocking.

func (*SerialConn) Read

func (c *SerialConn) Read(b []byte) (n int, err error)

Read reads data from the connection. TODO: implement the full method functionality: Read can be made to time out and return an Error with Timeout() == true after a fixed time limit; see SetDeadline and SetReadDeadline.

func (*SerialConn) SetDeadline

func (c *SerialConn) SetDeadline(t time.Time) error

SetDeadline sets the read and write deadlines associated with the connection. It is equivalent to calling both SetReadDeadline and SetWriteDeadline.

A deadline is an absolute time after which I/O operations fail with a timeout (see type Error) instead of blocking. The deadline applies to all future and pending I/O, not just the immediately following call to Read or Write. After a deadline has been exceeded, the connection can be refreshed by setting a deadline in the future.

An idle timeout can be implemented by repeatedly extending the deadline after successful Read or Write calls.

A zero value for t means I/O operations will not time out.

func (*SerialConn) SetReadDeadline

func (c *SerialConn) SetReadDeadline(t time.Time) error

SetReadDeadline sets the deadline for future Read calls and any currently-blocked Read call. A zero value for t means Read will not time out.

func (*SerialConn) SetWriteDeadline

func (c *SerialConn) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the deadline for future Write calls and any currently-blocked Write call. Even if write times out, it may return n > 0, indicating that some of the data was successfully written. A zero value for t means Write will not time out.

func (*SerialConn) Write

func (c *SerialConn) Write(b []byte) (n int, err error)

Write writes data to the connection. TODO: implement the full method functionality for timeouts. Write can be made to time out and return an Error with Timeout() == true after a fixed time limit; see SetDeadline and SetWriteDeadline.

type TCPAddr

type TCPAddr struct {
	IP   IP
	Port int
	Zone string // IPv6 scoped addressing zone
}

TCPAddr here to serve as compatible type. until TinyGo can compile the net package.

func ResolveTCPAddr

func ResolveTCPAddr(network, address string) (*TCPAddr, error)

ResolveTCPAddr returns an address of TCP end point.

The network must be a TCP network name.

func (*TCPAddr) Network

func (a *TCPAddr) Network() string

Network returns the address's network name, "tcp".

func (*TCPAddr) String

func (a *TCPAddr) String() string

type TCPSerialConn

type TCPSerialConn struct {
	SerialConn
	// contains filtered or unexported fields
}

TCPSerialConn is a loosely net.Conn compatible intended to support TCP over serial.

func DialTCP

func DialTCP(network string, laddr, raddr *TCPAddr) (*TCPSerialConn, error)

DialTCP makes a TCP network connection. raadr is the port that the messages will be sent to, and laddr is the port that will be listened to in order to receive incoming messages.

func NewTCPSerialConn

func NewTCPSerialConn(c SerialConn, laddr, raddr *TCPAddr) *TCPSerialConn

NewTCPSerialConn returns a new TCPSerialConn/

func (*TCPSerialConn) LocalAddr

func (c *TCPSerialConn) LocalAddr() Addr

LocalAddr returns the local network address.

func (*TCPSerialConn) RemoteAddr

func (c *TCPSerialConn) RemoteAddr() Addr

RemoteAddr returns the remote network address.

type UDPAddr

type UDPAddr struct {
	IP   IP
	Port int
	Zone string // IPv6 scoped addressing zone; added in Go 1.1
}

UDPAddr here to serve as compatible type. until TinyGo can compile the net package.

func ResolveUDPAddr

func ResolveUDPAddr(network, address string) (*UDPAddr, error)

ResolveUDPAddr returns an address of UDP end point.

The network must be a UDP network name.

func (*UDPAddr) Network

func (a *UDPAddr) Network() string

Network returns the address's network name, "udp".

func (*UDPAddr) String

func (a *UDPAddr) String() string

type UDPSerialConn

type UDPSerialConn struct {
	SerialConn
	// contains filtered or unexported fields
}

UDPSerialConn is a loosely net.Conn compatible intended to support UDP over serial.

func DialUDP

func DialUDP(network string, laddr, raddr *UDPAddr) (*UDPSerialConn, error)

DialUDP makes a UDP network connection. raadr is the port that the messages will be sent to, and laddr is the port that will be listened to in order to receive incoming messages.

func ListenUDP

func ListenUDP(network string, laddr *UDPAddr) (*UDPSerialConn, error)

ListenUDP listens for UDP connections on the port listed in laddr.

func NewUDPSerialConn

func NewUDPSerialConn(c SerialConn, laddr, raddr *UDPAddr) *UDPSerialConn

NewUDPSerialConn returns a new UDPSerialConn/

func (*UDPSerialConn) LocalAddr

func (c *UDPSerialConn) LocalAddr() Addr

LocalAddr returns the local network address.

func (*UDPSerialConn) RemoteAddr

func (c *UDPSerialConn) RemoteAddr() Addr

RemoteAddr returns the remote network address.

Directories

Path Synopsis
Package mqtt is intended to provide compatible interfaces with the Paho mqtt library.
Package mqtt is intended to provide compatible interfaces with the Paho mqtt library.
Package tls is intended to provide a minimal set of compatible interfaces with the Go standard library's tls package.
Package tls is intended to provide a minimal set of compatible interfaces with the Go standard library's tls package.

Jump to

Keyboard shortcuts

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