pipe

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: Apache-2.0 Imports: 5 Imported by: 2

Documentation

Overview

Package fasthttputil provides utility functions for fasthttp.

Index

Constants

This section is empty.

Variables

View Source
var DefaultInMemoryListener = &Options{
	MaxAcceptConn: 1024 * 10,
	MaxPipeBuffer: 1024,
}
View Source
var ErrInmemoryListenerClosed = errors.New("InmemoryListener is already closed: use of closed network connection")

ErrInmemoryListenerClosed indicates that the InmemoryListener is already closed.

View Source
var (
	// ErrTimeout is returned from Read() or Write() on timeout.
	ErrTimeout = &timeoutError{}
)

Functions

This section is empty.

Types

type InmemoryListener

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

func NewInmemoryListener

func NewInmemoryListener(opts *Options) *InmemoryListener

NewInmemoryListener returns new in-memory dialer<->net.Listener.

func (*InmemoryListener) Accept

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

Accept implements net.Listener's Accept.

It is safe calling Accept from concurrently running goroutines.

Accept returns new connection per each Dial call.

func (*InmemoryListener) Addr

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

Addr implements net.Listener's Addr.

func (*InmemoryListener) Close

func (ln *InmemoryListener) Close() error

Close implements net.Listener's Close.

func (*InmemoryListener) Dial

func (ln *InmemoryListener) Dial() (net.Conn, error)

Dial creates new client<->server connection. Just like a real Dial it only returns once the server has accepted the connection.

It is safe calling Dial from concurrently running goroutines.

type Options

type Options struct {
	MaxAcceptConn int
	MaxPipeBuffer int
}

InmemoryListener provides in-memory dialer<->net.Listener implementation.

It may be used either for fast in-process client<->server communications without network stack overhead or for client<->server tests.

type Pipe

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

func NewPipe

func NewPipe(name string) *Pipe

func (*Pipe) Address

func (p *Pipe) Address() string

func (*Pipe) Dial

func (p *Pipe) Dial(network, address string) (net.Conn, error)

func (*Pipe) IsClosed

func (p *Pipe) IsClosed() bool

func (*Pipe) Name

func (p *Pipe) Name() string

func (*Pipe) SetShutdown

func (p *Pipe) SetShutdown()

type PipeConns

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

PipeConns provides bi-directional connection pipe, which use in-process memory as a transport.

PipeConns must be created by calling NewPipeConns.

PipeConns has the following additional features comparing to connections returned from net.Pipe():

  • It is faster.
  • It buffers Write calls, so there is no need to have concurrent goroutine calling Read in order to unblock each Write call.
  • It supports read and write deadlines.

PipeConns is NOT safe for concurrent use by multiple goroutines!

func NewPipeConns

func NewPipeConns(chanSize int) *PipeConns

NewPipeConns returns new bi-directional connection pipe.

PipeConns is NOT safe for concurrent use by multiple goroutines!

func (*PipeConns) Close

func (pc *PipeConns) Close() error

Close closes pipe connections.

func (*PipeConns) Conn1

func (pc *PipeConns) Conn1() net.Conn

Conn1 returns the first end of bi-directional pipe.

Data written to Conn1 may be read from Conn2. Data written to Conn2 may be read from Conn1.

func (*PipeConns) Conn2

func (pc *PipeConns) Conn2() net.Conn

Conn2 returns the second end of bi-directional pipe.

Data written to Conn2 may be read from Conn1. Data written to Conn1 may be read from Conn2.

Jump to

Keyboard shortcuts

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