bytecounter

package
v3.12.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2021 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package bytecounter contains code to track the number of bytes sent and received by a probe.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	// net.Conn is the underlying net.Conn.
	net.Conn

	// Counter is the byte counter.
	Counter *Counter
}

Conn wraps a network connection and counts bytes.

func (*Conn) Read

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

Read implements net.Conn.Read.

func (*Conn) Write

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

Write implements net.Conn.Write.

type Counter

type Counter struct {
	// Received contains the bytes received. You MUST initialize
	// this field, or you can just use the New factory.
	Received *atomicx.Int64

	// Sent contains the bytes sent. You MUST initialize
	// this field, or you can just use the New factory.
	Sent *atomicx.Int64
}

Counter counts bytes sent and received.

func New

func New() *Counter

New creates a new Counter.

func (*Counter) BytesReceived

func (c *Counter) BytesReceived() int64

BytesReceived returns the bytes received so far.

func (*Counter) BytesSent

func (c *Counter) BytesSent() int64

BytesSent returns the bytes sent so far.

func (*Counter) CountBytesReceived

func (c *Counter) CountBytesReceived(count int)

CountBytesReceived adds count to the bytes received counter.

func (*Counter) CountBytesSent

func (c *Counter) CountBytesSent(count int)

CountBytesSent adds count to the bytes sent counter.

func (*Counter) CountKibiBytesReceived

func (c *Counter) CountKibiBytesReceived(count float64)

CountKibiBytesReceived adds 1024*count to the bytes received counter.

func (*Counter) CountKibiBytesSent

func (c *Counter) CountKibiBytesSent(count float64)

CountKibiBytesSent adds 1024*count to the bytes sent counter.

func (*Counter) KibiBytesReceived

func (c *Counter) KibiBytesReceived() float64

KibiBytesReceived returns the KiB received so far.

func (*Counter) KibiBytesSent

func (c *Counter) KibiBytesSent() float64

KibiBytesSent returns the KiB sent so far.

Jump to

Keyboard shortcuts

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