= keyring: getmsg, sendmsg, senderrmsg: send and receive messages on undelimited streams include "keyring.m"; keyring := load Keyring Keyring->PATH; getmsg: fn(fd: ref Sys->FD): array of byte; sendmsg: fn(fd: ref Sys->FD, buf: array of byte, n: int): int; senderrmsg: fn(fd: ref Sys->FD, s: string): int;These functions allow arbitrary data, packed into arrays ofbytes, to be exchanged on network connections using connec‐tion-oriented transport protocols that do not preserve recordboundaries (eg, TCP/IP without ssl(3)). They are used toimplement various authentication protocols, includingauth(6), as implemented by keyring-auth(2).Each data message is transmitted with a five-byte header con‐taining a four-character zero-padded decimal count n termi‐nated by a newline, followed by n bytes of message data. Anerror message has a similar structure, except that the firstcharacter of the count is replaced by an exclamation mark(!); the message data following contains the diagnosticstring in its UTF-8 encoding (see utf(6)).Getmsg reads the next message from fd and returns its datacontent.Sendmsg sends the first n bytes of buf as a message on fd,and returns n.Senderrmsg sends the error message s.== source/libinterp/keyring.c== diagnosticsSendmsg and senderrmsg return -1 if there was an error writ‐ing to fd; they set the system error string. Getmsg returnsnil if there was an error reading from fd; it sets the systemerror string to reflect the cause. It also returns nil if anerror message was received instead of a data message; thesystem error string will contain the error message's diagnos‐tic.
= keyring: getmsg, sendmsg, senderrmsg: send and receive messages on undelimited streams
include "keyring.m";
keyring := load Keyring Keyring->PATH;
getmsg: fn(fd: ref Sys->FD): array of byte;
sendmsg: fn(fd: ref Sys->FD, buf: array of byte, n: int): int;
senderrmsg: fn(fd: ref Sys->FD, s: string): int;
These functions allow arbitrary data, packed into arrays of
bytes, to be exchanged on network connections using connec‐
tion-oriented transport protocols that do not preserve record
boundaries (eg, TCP/IP without ssl(3)). They are used to
implement various authentication protocols, including
auth(6), as implemented by keyring-auth(2).
Each data message is transmitted with a five-byte header con‐
taining a four-character zero-padded decimal count n termi‐
nated by a newline, followed by n bytes of message data. An
error message has a similar structure, except that the first
character of the count is replaced by an exclamation mark
(!); the message data following contains the diagnostic
string in its UTF-8 encoding (see utf(6)).
Getmsg reads the next message from fd and returns its data
content.
Sendmsg sends the first n bytes of buf as a message on fd,
and returns n.
Senderrmsg sends the error message s.
== source
/libinterp/keyring.c
== diagnostics
Sendmsg and senderrmsg return -1 if there was an error writ‐
ing to fd; they set the system error string. Getmsg returns
nil if there was an error reading from fd; it sets the system
error string to reflect the cause. It also returns nil if an
error message was received instead of a data message; the
system error string will contain the error message's diagnos‐
tic.