delayconn

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package delayconn implements many smart net.Conn.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OneByteWriter

func OneByteWriter(w io.Writer) io.Writer

OneByteWriter returns a writer

Types

type DelayConn

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

DelayConn delay the read and write operations.

func NewDelayConn

func NewDelayConn(delay time.Duration, conn net.Conn) *DelayConn

NewDelayConn creates a new DelayConn.

func (*DelayConn) Close

func (rc *DelayConn) Close() error

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

func (*DelayConn) LocalAddr

func (rc *DelayConn) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (*DelayConn) Read

func (rc *DelayConn) Read(b []byte) (n int, err error)

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.

func (*DelayConn) RemoteAddr

func (rc *DelayConn) RemoteAddr() net.Addr

RemoteAddr returns the remote network address.

func (*DelayConn) SetDeadline

func (rc *DelayConn) 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.

Note that if a TCP connection has keep-alive turned on, which is the default unless overridden by Dialer.KeepAlive or ListenConfig.KeepAlive, then a keep-alive failure may also return a timeout error. On Unix systems a keep-alive failure on I/O can be detected using errors.Is(err, syscall.ETIMEDOUT).

func (*DelayConn) SetReadDeadline

func (rc *DelayConn) 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 (*DelayConn) SetWriteDeadline

func (rc *DelayConn) 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 (*DelayConn) Write

func (rc *DelayConn) Write(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.

type OneByteReadConn

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

OneByteReadConn sets the delay for read operations.

func NewOneByteReadConn

func NewOneByteReadConn(conn net.Conn) *OneByteReadConn

func (*OneByteReadConn) Close

func (rc *OneByteReadConn) Close() error

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

func (*OneByteReadConn) LocalAddr

func (rc *OneByteReadConn) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (*OneByteReadConn) Read

func (rc *OneByteReadConn) Read(b []byte) (n int, err error)

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.

func (*OneByteReadConn) RemoteAddr

func (rc *OneByteReadConn) RemoteAddr() net.Addr

RemoteAddr returns the remote network address.

func (*OneByteReadConn) SetDeadline

func (rc *OneByteReadConn) 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.

Note that if a TCP connection has keep-alive turned on, which is the default unless overridden by Dialer.KeepAlive or ListenConfig.KeepAlive, then a keep-alive failure may also return a timeout error. On Unix systems a keep-alive failure on I/O can be detected using errors.Is(err, syscall.ETIMEDOUT).

func (*OneByteReadConn) SetReadDeadline

func (rc *OneByteReadConn) 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 (*OneByteReadConn) SetWriteDeadline

func (rc *OneByteReadConn) 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 (*OneByteReadConn) Write

func (rc *OneByteReadConn) Write(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.

type OneByteWriteConn

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

OneByteWriteConn guarantees write a one bytes every time.

func NewOneByteWriteConn

func NewOneByteWriteConn(conn net.Conn) *OneByteWriteConn

NewOneByteWriteConn creates a new OneByteWriteConn.

func (*OneByteWriteConn) Close

func (rc *OneByteWriteConn) Close() error

Close closes the connection. Any blocked Write or Write operations will be unblocked and return errors.

func (*OneByteWriteConn) LocalAddr

func (rc *OneByteWriteConn) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (*OneByteWriteConn) Read

func (rc *OneByteWriteConn) Read(b []byte) (n int, err error)

Write Writes data from 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.

func (*OneByteWriteConn) RemoteAddr

func (rc *OneByteWriteConn) RemoteAddr() net.Addr

RemoteAddr returns the remote network address.

func (*OneByteWriteConn) SetDeadline

func (rc *OneByteWriteConn) SetDeadline(t time.Time) error

SetDeadline sets the Write and write deadlines associated with the connection. It is equivalent to calling both SetWriteDeadline 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 Write 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 Write or Write calls.

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

Note that if a TCP connection has keep-alive turned on, which is the default unless overridden by Dialer.KeepAlive or ListenConfig.KeepAlive, then a keep-alive failure may also return a timeout error. On Unix systems a keep-alive failure on I/O can be detected using errors.Is(err, syscall.ETIMEDOUT).

func (*OneByteWriteConn) SetReadDeadline

func (rc *OneByteWriteConn) SetReadDeadline(t time.Time) error

SetReadDeadline sets the deadline for future Read calls

func (*OneByteWriteConn) SetWriteDeadline

func (rc *OneByteWriteConn) SetWriteDeadline(t time.Time) error

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

func (*OneByteWriteConn) Write

func (rc *OneByteWriteConn) Write(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.

type PerWriteDelayConn

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

PerWriteDelayConn implements the delay before Write.

func NewPerWriteDelayConn

func NewPerWriteDelayConn(delay time.Duration, conn net.Conn) *PerWriteDelayConn

NewPerWriteDelayConn returns a new PerWriteDelayConn.

func (*PerWriteDelayConn) Close

func (rc *PerWriteDelayConn) Close() error

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

func (*PerWriteDelayConn) LocalAddr

func (rc *PerWriteDelayConn) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (*PerWriteDelayConn) Read

func (rc *PerWriteDelayConn) Read(b []byte) (n int, err error)

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.

func (*PerWriteDelayConn) RemoteAddr

func (rc *PerWriteDelayConn) RemoteAddr() net.Addr

RemoteAddr returns the remote network address.

func (*PerWriteDelayConn) SetDeadline

func (rc *PerWriteDelayConn) 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.

Note that if a TCP connection has keep-alive turned on, which is the default unless overridden by Dialer.KeepAlive or ListenConfig.KeepAlive, then a keep-alive failure may also return a timeout error. On Unix systems a keep-alive failure on I/O can be detected using errors.Is(err, syscall.ETIMEDOUT).

func (*PerWriteDelayConn) SetReadDeadline

func (rc *PerWriteDelayConn) 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 (*PerWriteDelayConn) SetWriteDeadline

func (rc *PerWriteDelayConn) 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 (*PerWriteDelayConn) Write

func (rc *PerWriteDelayConn) Write(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.

type ReadDelayConn

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

ReadDelayConn sets the read delay operations.

func NewReadDelayConn

func NewReadDelayConn(delay time.Duration, conn net.Conn) *ReadDelayConn

NewReadDelayConn creates a new ReadDelayConn.

func (*ReadDelayConn) Close

func (rc *ReadDelayConn) Close() error

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

func (*ReadDelayConn) LocalAddr

func (rc *ReadDelayConn) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (*ReadDelayConn) Read

func (rc *ReadDelayConn) Read(b []byte) (n int, err error)

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.

func (*ReadDelayConn) RemoteAddr

func (rc *ReadDelayConn) RemoteAddr() net.Addr

RemoteAddr returns the remote network address.

func (*ReadDelayConn) SetDeadline

func (rc *ReadDelayConn) 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.

Note that if a TCP connection has keep-alive turned on, which is the default unless overridden by Dialer.KeepAlive or ListenConfig.KeepAlive, then a keep-alive failure may also return a timeout error. On Unix systems a keep-alive failure on I/O can be detected using errors.Is(err, syscall.ETIMEDOUT).

func (*ReadDelayConn) SetReadDeadline

func (rc *ReadDelayConn) 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 (*ReadDelayConn) SetWriteDeadline

func (rc *ReadDelayConn) 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 (*ReadDelayConn) Write

func (rc *ReadDelayConn) Write(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.

type WriteDelayConn

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

WriteDelayConn implements the delay before Write.

func NewWriteDelayConn

func NewWriteDelayConn(delay time.Duration, conn net.Conn) *WriteDelayConn

NewWriteDelayConn returns a new WriteDelayConn.

func (*WriteDelayConn) Close

func (rc *WriteDelayConn) Close() error

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

func (*WriteDelayConn) LocalAddr

func (rc *WriteDelayConn) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (*WriteDelayConn) Read

func (rc *WriteDelayConn) Read(b []byte) (n int, err error)

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.

func (*WriteDelayConn) RemoteAddr

func (rc *WriteDelayConn) RemoteAddr() net.Addr

RemoteAddr returns the remote network address.

func (*WriteDelayConn) SetDeadline

func (rc *WriteDelayConn) 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.

Note that if a TCP connection has keep-alive turned on, which is the default unless overridden by Dialer.KeepAlive or ListenConfig.KeepAlive, then a keep-alive failure may also return a timeout error. On Unix systems a keep-alive failure on I/O can be detected using errors.Is(err, syscall.ETIMEDOUT).

func (*WriteDelayConn) SetReadDeadline

func (rc *WriteDelayConn) 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 (*WriteDelayConn) SetWriteDeadline

func (rc *WriteDelayConn) 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 (*WriteDelayConn) Write

func (rc *WriteDelayConn) Write(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.

Jump to

Keyboard shortcuts

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