include "msgio.m"; msgio := load Msgio Msgio->PATH; init: fn(); 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; getstring: fn(fd: ref Sys->FD): (string, string); putstring: fn(fd: ref Sys->FD, s: string): int; getbytearray: fn(fd: ref Sys->FD): (array of byte, string); putbytearray: fn(fd: ref Sys->FD, a: array of byte, n: int): int; puterror: fn(fd: ref Sys->FD, s: string): int;
Init must be called before any other operation of the module.
The first set allows arbitrary data, packed into arrays of bytes, to be exchanged on network connections using protocols such as TCP/IP that do not preserve record boundaries. They are used to implement various authentication protocols, including auth(6).
Each data message is transmitted with a five-byte header containing a four-character zero-padded decimal count n terminated 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.
The second set of functions provide I/O for strings, byte arrays and error strings over network connections that provide a record structure for communication (as provided for arbitrary networks by ssl(3)).
Putstring writes string s to fd. It returns the number of bytes written, or -1 if an error occurred. Messages written by putstring are truncated to 4096 bytes.
Getstring reads a string as written by putstring from fd and returns a tuple (result,error). If successful, the error string is nil.
Putbytearray writes the array of bytes a to fd. It returns the number of bytes written, or -1 if an error occurred. Messages written by putbytearray are truncated to 4096 bytes.
Getbytearray reads an array of bytes as written by putbytearray from fd and returns a tuple of the form (result,error). If successful, the error string is nil.
Puterror writes an error string s to fd. It can be used in place of putstring or putbytearray to cause a corresponding getstring or getbytearray to fail (in the receiving process), forcing them to return the error string s. It may not be longer than Sys->ERRMAX bytes.
MSGIO(2 ) | Rev: Tue Mar 31 02:42:39 GMT 2015 |