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 ¶
var ( TCPOptions = append([]string{"escape", "expect", "max", "read", "tls", "until"}, tlsconf.Keys...) UDPOptions = append([]string{"escape", "expect", "reply"}, tlsconf.Keys...) )
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 ¶
Types ¶
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
Driver is a raw TCP or UDP protocol.Protocol.
func NewTCP ¶
NewTCP returns a Driver for target. target.URL is tcp://host:port or a bare host:port.
func NewUDP ¶
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 ¶
Close implements protocol.Protocol. Do opens and closes its own connection every call, so Driver holds nothing to release.
func (*Driver) Do ¶
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.