fakenet

package
v0.0.0-...-e91a9a7 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

The fakenet package provides a way to turn a regular io.ReadWriter into a net.Conn, including support for timeouts.

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("operation on closed channel")

Functions

func NewConn

func NewConn(r io.ReadCloser, w io.WriteCloser, local, remote net.Addr) net.Conn

NewConn returns a net.Conn using r for reading and w for writing.

Local and remote give the addresses that will be returned from the respective methods of the connection. If either is nil, Addr("fakenet") will be used.

func NewListener

func NewListener(addr net.Addr) (chan<- net.Conn, net.Listener)

NewListener creates a new net.Listener and returns a channel on which it reads connections and gives to callers of Accept. The Listener returns addr for its address (or Addr("fakenet") if nil).

Types

type Addr

type Addr string

func (Addr) Network

func (a Addr) Network() string

func (Addr) String

func (a Addr) String() string

type ChanReader

type ChanReader struct {
	// contains filtered or unexported fields
}

A ChanReader reads from a chan []byte to satisfy Read requests.

func NewChanReader

func NewChanReader(c <-chan []byte) *ChanReader

NewChanReader creates a new ChanReader that reads from the given channel.

func (*ChanReader) Close

func (r *ChanReader) Close() error

Close implements the net.Conn Close method.

func (*ChanReader) Read

func (r *ChanReader) Read(buf []byte) (int, error)

Read implements the net.Conn Read method.

func (*ChanReader) SetReadDeadline

func (r *ChanReader) SetReadDeadline(t time.Time) error

SetReadDeadline implements the net.Conn SetReadDeadline method.

type ChanWriter

type ChanWriter struct {
	// contains filtered or unexported fields
}

A ChanWriter writes to a chan []byte to satisfy Write requests.

func NewChanWriter

func NewChanWriter(c chan<- []byte) *ChanWriter

NewChanWriter creates a new ChanWriter that writes to the given channel.

func (*ChanWriter) Close

func (w *ChanWriter) Close() error

Close implements the net.Conn Close method.

func (*ChanWriter) SetWriteDeadline

func (w *ChanWriter) SetWriteDeadline(t time.Time) error

SetWriteDeadline implements the net.Conn SetWriteDeadline method.

func (*ChanWriter) Write

func (w *ChanWriter) Write(buf []byte) (n int, err error)

Write implements the net.Conn Write method.

Jump to

Keyboard shortcuts

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