socket

package
v0.7.0-alpha Latest Latest
Warning

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

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

README

socket

This package provides some helper function to abuse network sockets and do weird things, including but not limited to:

  • Spawning connection pairs
  • Wrap a readable/writable interface into a net.Conn

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TCPConnFileWrap

func TCPConnFileWrap(wrapped any) (wrapperFile *os.File, ctxCancel context.Context, err error)

TCPConnFileWrap wraps an object into a *os.File from an underlying net.TCPConn. The object must implement io.Reader and/or io.Writer.

If the object implements io.Reader, upon completing copying the object to the returned *os.File, the callback functions will be called.

It is caller's responsibility to close the returned *os.File.

func TCPConnPair

func TCPConnPair(address ...string) (c1, c2 *net.TCPConn, err error)

TCPConnPair returns a pair of connected net.TCPConn.

func TCPConnWrap

func TCPConnWrap(wrapped any) (wrapperConn *net.TCPConn, ctxCancel context.Context, err error)

TCPConnWrap wraps an io.Reader/io.Writer/io.Closer interface into a TCPConn.

This function spins up goroutine(s) to copy data between the ReadWrite(Close)r and the TCPConn. Anything written to the TCPConn by caller will be written to the wrapped object if the object implements io.Writer, and if the object implements io.Reader, anything read by goroutine from the wrapped object will be readable from the TCPConn by caller.

Once this function is invoked, the caller should not perform I/O operations on the wrapped connection anymore.

The returned context.Context can be used to check if the connection is still alive. If the connection is closed, the context will be canceled.

func UnixConnFileWrap

func UnixConnFileWrap(wrapped any) (wrapperFile *os.File, ctxCancel context.Context, err error)

UnixConnFileWrap wraps an object into a *os.File from an underlying net.UnixConn. The object must implement io.Reader and/or io.Writer.

If the object implements io.Reader, upon completing copying the object to the returned *os.File, the callback functions will be called.

It is caller's responsibility to close the returned *os.File.

func UnixConnPair

func UnixConnPair(path ...string) (*net.UnixConn, *net.UnixConn, error)

UnixConnPair returns a pair of connected net.UnixConn.

func UnixConnWrap

func UnixConnWrap(wrapped any) (wrapperConn *net.UnixConn, ctxCancel context.Context, err error)

UnixConnWrap wraps an io.Reader/io.Writer/io.Closer interface into a UnixConn.

This function spins up goroutine(s) to copy data between the ReadWrite(Close)r and the UnixConn. Anything written to the UnixConn by caller will be written to the wrapped object if the object implements io.Writer, and if the object implements io.Reader, anything read by goroutine from the wrapped object will be readable from the UnixConn by caller.

Once this function is invoked, the caller should not perform I/O operations on the wrapped connection anymore.

The returned context.Context can be used to check if the connection is still alive. If the connection is closed, the context will be canceled.

Types

This section is empty.

Jump to

Keyboard shortcuts

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