timeoutconn

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

package timeoutconn wraps a Wire to provide idle timeouts based on Set{Read,Write}Deadline. Additionally, it exports abstractions for vectored I/O.

Index

Constants

This section is empty.

Variables

View Source
var SyscallConnNotSupported = errors.New("SyscallConn not supported")

Functions

This section is empty.

Types

type Conn

type Conn struct {
	Wire
	// contains filtered or unexported fields
}

func Wrap

func Wrap(conn Wire, idleTimeout time.Duration) Conn

func (*Conn) DisableTimeouts

func (c *Conn) DisableTimeouts() error

DisableTimeouts disables the idle timeout behavior provided by this package. Existing deadlines are cleared iff the call is the first call to this method.

func (Conn) Read

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

func (Conn) ReadvFull

func (c Conn) ReadvFull(buffers net.Buffers) (n int64, err error)

Reads the given buffers full: Think of io.ReadvFull, but for net.Buffers + using the readv syscall.

If the underlying Wire is not a SyscallConner, a fallback ipmlementation based on repeated Conn.Read invocations is used.

If the connection returned io.EOF, the number of bytes up ritten until then + io.EOF is returned. This behavior is different to io.ReadFull which returns io.ErrUnexpectedEOF.

func (*Conn) RenewWriteDeadline added in v0.1.1

func (c *Conn) RenewWriteDeadline() error

func (Conn) Write

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

func (Conn) WritevFull

func (c Conn) WritevFull(bufs net.Buffers) (n int64, err error)

Writes the given buffers to Conn, following the sematincs of io.Copy, but is guaranteed to use the writev system call if the wrapped Wire support it. Note the Conn does not support writev through io.Copy(aConn, aNetBuffers).

type SyscallConner

type SyscallConner interface {
	// The sentinel error value SyscallConnNotSupported can be returned
	// if the support for SyscallConn depends on runtime conditions and
	// that runtime condition is not met.
	SyscallConn() (syscall.RawConn, error)
}

The interface that must be implemented for vectored I/O support. If the wrapped Wire does not implement it, a less efficient fallback implementation is used. Rest assured that Go's *net.TCPConn implements this interface.

type Wire

type Wire interface {
	net.Conn
	// A call to CloseWrite indicates that no further Write calls will be made to Wire.
	// The implementation must return an error in case of Write calls after CloseWrite.
	// On the peer's side, after it read all data written to Wire prior to the call to
	// CloseWrite on our side, the peer's Read calls must return io.EOF.
	// CloseWrite must not affect the read-direction of Wire: specifically, the
	// peer must continue to be able to send, and our side must continue be
	// able to receive data over Wire.
	//
	// Note that CloseWrite may (and most likely will) return sooner than the
	// peer having received all data written to Wire prior to CloseWrite.
	// Note further that buffering happening in the network stacks on either side
	// mandates an explicit acknowledgement from the peer that the connection may
	// be fully shut down: If we call Close without such acknowledgement, any data
	// from peer to us that was already in flight may cause connection resets to
	// be sent from us to the peer via the specific transport protocol. Those
	// resets (e.g. RST frames) may erase all connection context on the peer,
	// including data in its receive buffers. Thus, those resets are in race with
	// a) transmission of data written prior to CloseWrite and
	// b) the peer application reading from those buffers.
	//
	// The WaitForPeerClose method can be used to wait for connection termination,
	// iff the implementation supports it. If it does not, the only reliable way
	// to wait for a peer to have read all data from Wire (until io.EOF), is to
	// expect it to close the wire at that point as well, and to drain Wire until
	// we also read io.EOF.
	CloseWrite() error
}

Directories

Path Synopsis
internal
wireevaluator
a tool to test whether a given transport implements the timeoutconn.Wire interface
a tool to test whether a given transport implements the timeoutconn.Wire interface

Jump to

Keyboard shortcuts

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