Movatterモバイル変換


[0]ホーム

URL:


memnet

package
v1.92.2Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License:BSD-3-ClauseImports:13Imported by:2

Details

Repository

github.com/tailscale/tailscale

Links

Documentation

Overview

Package memnet implements an in-memory network implementation.It is useful for dialing and listening on in-memory addressesin tests and other situations where you don't want to use thenetwork.

Index

Constants

View Source
const NetworkName = "mem"

NetworkName is the network name returned bynet.Addr.Networkfornet.Conn.LocalAddr andnet.Conn.RemoteAddr from theConn type.

Variables

This section is empty.

Functions

funcNewConn

func NewConn(namestring, maxBufint) (Conn,Conn)

NewConn creates a pair of Conns that are wired together by pipes.

funcNewTCPConn

func NewTCPConn(src, dstnetip.AddrPort, maxBufint) (localConn, remoteConn)

NewTCPConn creates a pair of Conns that are wired together by pipes.

Types

typeConn

type Conn interface {net.Conn// SetReadBlock blocks or unblocks the Read method of this Conn.// It reports an error if the existing value matches the new value,// or if the Conn has been Closed.SetReadBlock(bool)error// SetWriteBlock blocks or unblocks the Write method of this Conn.// It reports an error if the existing value matches the new value,// or if the Conn has been Closed.SetWriteBlock(bool)error}

Conn is a net.Conn that can additionally have its reads and writes blocked and unblocked.

typeListener

type Listener struct {// NewConn, if non-nil, is called to create a new pair of connections// when dialing. If nil, NewConn is used.NewConn func(network, addrstring, maxBufint) (Conn,Conn)// contains filtered or unexported fields}

Listener is a net.Listener using NewConn to create pairs of networkconnections connected in memory using a buffered pipe. It also provides aDial method to establish new connections.

funcListen

func Listen(addrstring) *Listener

Listen returns a new Listener for the provided address.

func (*Listener)Accept

func (ln *Listener) Accept() (net.Conn,error)

Accept blocks until a new connection is available or the listener is closed.

func (*Listener)Addr

func (ln *Listener) Addr()net.Addr

Addr implements net.Listener.Addr.

func (*Listener)Close

func (ln *Listener) Close()error

Close closes the pipe listener.

func (*Listener)Dial

func (ln *Listener) Dial(ctxcontext.Context, network, addrstring) (_net.Conn, errerror)

Dial connects to the listener using the provided context.The provided Context must be non-nil. If the context expires before theconnection is complete, an error is returned. Once successfully connectedany expiration of the context will not affect the connection.

typeNetworkadded inv1.84.0

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

Network implementsNetwork using an in-memory network, usuallyused for testing.

As of 2025-04-08, it only supports TCP.

Its zero value is a validnetx.Network implementation.

func (*Network)Dialadded inv1.84.0

func (m *Network) Dial(ctxcontext.Context, network, addressstring) (net.Conn,error)

func (*Network)Listenadded inv1.84.0

func (m *Network) Listen(network, addressstring) (net.Listener,error)

func (*Network)NewLocalTCPListeneradded inv1.84.0

func (m *Network) NewLocalTCPListener()net.Listener

typePipe

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

Pipe implements an in-memory FIFO with timeouts.

funcNewPipe

func NewPipe(namestring, maxBufint) *Pipe

NewPipe creates a Pipe with a buffer size fixed at maxBuf.

func (*Pipe)Block

func (p *Pipe) Block()error

Block will cause all calls to Read and Write to block until they eithertimeout, are unblocked or the pipe is closed.

func (*Pipe)Close

func (p *Pipe) Close()error

Close closes the pipe.

func (*Pipe)Read

func (p *Pipe) Read(b []byte) (nint, errerror)

Read implements io.Reader.Once the buffer is drained (i.e. after Close), subsequent calls willreturn io.EOF.

func (*Pipe)SetReadDeadline

func (p *Pipe) SetReadDeadline(ttime.Time)error

SetReadDeadline sets the deadline for future Read calls.

func (*Pipe)SetWriteDeadline

func (p *Pipe) SetWriteDeadline(ttime.Time)error

SetWriteDeadline sets the deadline for future Write calls.

func (*Pipe)Unblock

func (p *Pipe) Unblock()error

Unblock will cause all blocked Read/Write calls to continue execution.

func (*Pipe)Write

func (p *Pipe) Write(b []byte) (nint, errerror)

Write implements io.Writer.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp