network

package
v0.76.3 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ByteOrder = binary.LittleEndian

ByteOrder is the byte order.

Functions

func Connect

func Connect(pid int, dial DialFunc, glob GlobFunc) (net.Conn, error)

Connect opens an IPC connection to a local dotnet process, given a PID. On Mac/Linux, this is a Unix domain socket. Windows (TBD) will use a named pipe. DialFunc and GlobFunc are swappable for testing.

func ReadBlobData added in v0.22.0

func ReadBlobData(dir string, numFiles int) ([][]byte, error)

ReadBlobData is intended for reading binary blobs for testing. It reads the passed-in number of files using a naming convention and returns them as byte arrays for use by a BlobReader.

func WriteUTF16String

func WriteUTF16String(buf *bytes.Buffer, s string)

WriteUTF16String writes a length-prefixed, zero-terminated utf16 string to the passed-in buffer

Types

type BlobReader added in v0.22.0

type BlobReader struct {
	WriteBuf []byte
	// contains filtered or unexported fields
}

BlobReader implements io.ReadWriter and can fake a socket from files saved by BlobWriter. It can also return errors for testing purposes.

func NewBlobReader added in v0.22.0

func NewBlobReader(data [][]byte) *BlobReader

func (*BlobReader) ErrOnRead added in v0.23.0

func (r *BlobReader) ErrOnRead(i int)

ErrOnRead will cause a call to Read to return an error at the specified readCount.

func (*BlobReader) Gate added in v0.23.0

func (r *BlobReader) Gate() chan struct{}

func (*BlobReader) Read added in v0.22.0

func (r *BlobReader) Read(p []byte) (int, error)

Read reads the appropriate number of bytes into the passed in slice, from the member byte arrays, maintaining a count of how many times it was called. If the count matches the errOn field's value, an error is returned.

func (*BlobReader) StopOnRead added in v0.23.0

func (r *BlobReader) StopOnRead(i int)

func (*BlobReader) Write added in v0.22.0

func (r *BlobReader) Write(p []byte) (n int, err error)

type BlobWriter added in v0.23.0

type BlobWriter interface {
	Init() error
	// contains filtered or unexported methods
}

BlobWriter is an interface extracted from blobFileWriter so that it can be swapped with a NopBlobWriter.

func NewBlobWriter added in v0.23.0

func NewBlobWriter(blobDir string, maxBlobFiles int, logger *zap.Logger) BlobWriter

type DialFunc

type DialFunc func(network, address string) (net.Conn, error)

type FakeRW added in v0.22.0

type FakeRW struct {
	WriteErrIdx int
	Writes      []byte

	ReadErrIdx int
	Responses  map[int][]byte
	// contains filtered or unexported fields
}

FakeRW fakes an io.ReadWriter for testing.

func NewDefaultFakeRW added in v0.22.0

func NewDefaultFakeRW(magic, nettrace, fastSerialization string) *FakeRW

func (*FakeRW) Read added in v0.22.0

func (rw *FakeRW) Read(p []byte) (n int, err error)

func (*FakeRW) Write added in v0.22.0

func (rw *FakeRW) Write(p []byte) (n int, err error)

type GlobFunc

type GlobFunc func(pattern string) (matches []string, err error)

type MultiReader added in v0.22.0

type MultiReader interface {
	// ReadByte reads and returns a single byte from the stream
	ReadByte() (byte, error)
	// ReadCompressedInt32 reads a compressed int32 from the stream
	ReadCompressedInt32() (int32, error)
	// ReadCompressedUInt32 reads a compressed uint32 from the stream
	ReadCompressedUInt32() (uint32, error)
	// ReadCompressedInt64 reads a compressed int64 from the stream
	ReadCompressedInt64() (int64, error)
	// ReadCompressedUInt64 reads a compressed uint64 from the stream
	ReadCompressedUInt64() (uint64, error)
	// Read reads bytes from the underlying stream into the passed in reference
	Read(interface{}) error
	// ReadUTF16 reads and returns a zero-terminated UTF16 string from the stream
	ReadUTF16() (string, error)
	// ReadASCII reads an ASCII string of the given length from the underlying stream
	ReadASCII(int) (string, error)
	// AssertNextByteEquals reads the next byte and returns an error if it doesn't
	// equal the passed in byte
	AssertNextByteEquals(byte) error
	// Seek moves the current position forward by reading and throwing away the
	// specified number of bytes
	Seek(i int) error
	// Align moves the current position forward for 4-byte alignment
	// https://github.com/Microsoft/perfview/blob/main/src/TraceEvent/EventPipe/EventPipeFormat.md
	Align() error
	// Pos returns the position (byte offset) from the underlying PositionalReader
	Pos() int
	// Reset resets the underlying PositionalReader
	Reset()
	// Flush flushes the underlying BlobWriter
	Flush()
}

MultiReader provides an abstraction to make reading from the diagnostics stream easier for callers.

func NewMultiReader added in v0.22.0

func NewMultiReader(r io.Reader, bw BlobWriter) MultiReader

type NopBlobWriter added in v0.23.0

type NopBlobWriter struct{}

NopBlobWriter implements BlobWriter but does nothing.

func (*NopBlobWriter) Init added in v0.23.0

func (w *NopBlobWriter) Init() error

type PositionalReader added in v0.22.0

type PositionalReader interface {
	Read(p []byte) (n int, err error)
	Position() int
	Flush()
	Reset()
}

PositionalReader is an interface extracted from posReader so it can be swapped for testing. It implements io.Reader, can return the number of bytes read, and can reset the current position.

func NewPositionalReader added in v0.22.0

func NewPositionalReader(r io.Reader, w BlobWriter) PositionalReader

NewPositionalReader creates a PositionalReader, wrapping the passed-in io.Reader, and keeping track of the number of bytes read.

Jump to

Keyboard shortcuts

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