socket

package
v0.7.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package socket implements the "tcp" and "udp" protocol.Protocol drivers: raw sockets, for a service that speaks its own wire protocol (a custom binary protocol, SMTP, Redis, a syslog or DNS port) and has no driver of its own.

Like the WebSocket driver, each call to Do opens its own connection, sends the body once, optionally reads a reply, and closes. That measures connect, send and reply time under load. It is not a long-lived session.

Options (set with -opt key=value):

escape   true (default) or false. When true, the text in -body,
         expect and until may use \n \r \t \0 \\ and \xNN.
read     TCP only. Read exactly this many bytes after sending.
until    TCP only. Read until this text has been received.
expect   The reply must contain this text. With TCP and neither read
         nor until, it reads until the text appears.
max      TCP only. Most bytes to read (default 1048576).
tls      TCP only. true to wrap the connection in TLS.
reply    UDP only. true to wait for one reply datagram.

Index

Constants

This section is empty.

Variables

View Source
var (
	TCPOptions = []string{"escape", "expect", "max", "read", "tls", "until"}
	UDPOptions = []string{"escape", "expect", "reply"}
)

TCPOptions and UDPOptions are the -opt keys each driver accepts. The command's protocol table uses the same lists, so the two cannot differ.

Functions

func Unescape

func Unescape(s string) ([]byte, error)

Unescape turns \n, \r, \t, \0, \\ and \xNN in s into the bytes they stand for. Any other backslash sequence is an error, so a typo is not sent silently.

Types

type Driver

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

Driver is a raw TCP or UDP protocol.Protocol.

func NewTCP

func NewTCP(target protocol.Target, timeout time.Duration) (*Driver, error)

NewTCP returns a Driver for target. target.URL is tcp://host:port or a bare host:port.

func NewUDP

func NewUDP(target protocol.Target, timeout time.Duration) (*Driver, error)

NewUDP returns a Driver for target. target.URL is udp://host:port or a bare host:port. A UDP run needs a body to send.

func (*Driver) Close

func (d *Driver) Close() error

Close implements protocol.Protocol. Do opens and closes its own connection every call, so Driver holds nothing to release.

func (*Driver) Do

func (d *Driver) Do(parent context.Context) (protocol.Result, error)

Do implements protocol.Protocol.

-timeout is one budget for the whole call: dial, send and read together. It is applied once, as a context around the call, the way the gRPC driver does it. The same context ends the call when the run ends, because context.AfterFunc closes the socket as soon as the context is done.

func (*Driver) Name

func (d *Driver) Name() string

Name implements protocol.Protocol.

func (*Driver) Run

func (d *Driver) Run(parent context.Context) (protocol.Result, []byte)

Run is Do, and it also returns the reply that was read, even when the call failed after some bytes came in. A load test does not need the reply. A scenario script does.

Jump to

Keyboard shortcuts

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