nupp.runtime.services.net

Provider protocol for host.net API 1.

Setup imports service here without opening sockets, then selects an implementation before requiring nupp.io.net. The facade retains the provider table and supplies it as the explicit receiver for every operation. Provider handles are opaque; shared Address values come from nupp.io.net.types.

Listener acceptance, connection completion, and stream I/O are readiness probes. They must not run a private blocking loop. run(timeoutMs) pumps the provider's reactor, and the public facade exposes pumping as nupp.io.net.pump. Keep handle ownership separate for listeners, connect requests, streams, and datagrams.

Pending and EOF conventions differ by operation and are documented below. Report failures through the declared error result rather than disguising them as pending work. A TLS provider wrapping these streams must understand their handle representation; selection cannot make unrelated transport handles interoperable.

Module contents

Types

TypeKindDescription
Providerinterface

Values

ValueKindDescription
servicevariableCanonical host.net API 1 handle; setup selects before the public facade loads.

Types#

Providerinterface#

interface Provider
    readonly listen: function(
        self: Provider,
        host: string,
        port: integer,
        backlog: integer,
        reusePort: boolean
    ): (any?, string?)
    readonly listenPath: function(self: Provider, path: string, backlog: integer): (any?, string?)
    readonly listenerPort: function(self: Provider, listener: any): integer
    readonly accept: function(self: Provider, listener: any): (any?, string?)
    readonly closeListener: function(self: Provider, listener: any): nil
    readonly connect: function(self: Provider, host: string, port: integer, timeoutMs: integer): (any?, string?)
    readonly connectPath: function(self: Provider, path: string, timeoutMs: integer): (any?, string?)
    readonly connectPoll: function(self: Provider, request: any): (any?, string?)
    readonly closeConnect: function(self: Provider, request: any): nil
    readonly read: function(self: Provider, stream: any, wanted: integer): (string?, string?)
    readonly ended: function(self: Provider, stream: any): boolean
    readonly write: function(self: Provider, stream: any, bytes: string): (integer?, string?)
    readonly pending: function(self: Provider, stream: any): integer
    readonly writeFailed: function(self: Provider, stream: any): boolean
    readonly shuttingDown: function(self: Provider, stream: any): boolean
    readonly shutdownWrite: function(self: Provider, stream: any): (boolean, string?)
    readonly address: function(self: Provider, stream: any, peer: boolean): Address?
    readonly noDelay: function(self: Provider, stream: any, enable: boolean): (boolean, string?)
    readonly keepAlive: function(
        self: Provider,
        stream: any,
        enable: boolean,
        delaySeconds: integer
    ): (boolean, string?)
    readonly broadcast: function(self: Provider, socket: any, enable: boolean): (boolean, string?)
    readonly multicastTtl: function(self: Provider, socket: any, ttl: integer): (boolean, string?)
    readonly multicastLoop: function(self: Provider, socket: any, enable: boolean): (boolean, string?)
    readonly membership: function(
        self: Provider,
        socket: any,
        group: string,
        interfaceAddress: string,
        join: boolean
    ): (boolean, string?)
    readonly closeStream: function(self: Provider, stream: any): nil
    readonly bindDatagram: function(self: Provider, host: string, port: integer, reusePort: boolean): (any?, string?)
    readonly datagramPort: function(self: Provider, socket: any): integer
    readonly receive: function(
        self: Provider,
        socket: any,
        maximum: integer
    ): (string?, string?, integer?, boolean?, string?)
    readonly sendTo: function(
        self: Provider,
        socket: any,
        host: string,
        port: integer,
        bytes: string
    ): (boolean, string?)
    readonly closeDatagram: function(self: Provider, socket: any): nil
    readonly run: function(self: Provider, timeoutMs: integer): nil
end

Methods

listen#
listen: function(
    self: Provider,
    host: string,
    port: integer,
    backlog: integer,
    reusePort: boolean
): (any?, string?)

Creates a TCP listener; returns its handle or nil and an error.

Arguments
NameTypeDescription
selfProvider
hoststring
portinteger
backloginteger
reusePortboolean
Returns
TypeDescription
any?
string?
listenPath#
listenPath: function(self: Provider, path: string, backlog: integer): (any?, string?)

Creates a local-path listener with the requested backlog.

Arguments
NameTypeDescription
selfProvider
pathstring
backloginteger
Returns
TypeDescription
any?
string?
listenerPort#
listenerPort: function(self: Provider, listener: any): integer

Returns the bound port, or -1 when no IP port is available.

Arguments
NameTypeDescription
selfProvider
listenerany
Returns
TypeDescription
integer
accept#
accept: function(self: Provider, listener: any): (any?, string?)

Returns an accepted stream, nil while pending, or nil and an error.

Arguments
NameTypeDescription
selfProvider
listenerany
Returns
TypeDescription
any?
string?
closeListener#
closeListener: function(self: Provider, listener: any): nil

Releases a listener and its pending accept resources.

Arguments
NameTypeDescription
selfProvider
listenerany
Returns
TypeDescription
nil
connect#
connect: function(self: Provider, host: string, port: integer, timeoutMs: integer): (any?, string?)

Starts a TCP connection request with a millisecond timeout.

Arguments
NameTypeDescription
selfProvider
hoststring
portinteger
timeoutMsinteger
Returns
TypeDescription
any?
string?
connectPath#
connectPath: function(self: Provider, path: string, timeoutMs: integer): (any?, string?)

Starts a local-path connection request with a millisecond timeout.

Arguments
NameTypeDescription
selfProvider
pathstring
timeoutMsinteger
Returns
TypeDescription
any?
string?
connectPoll#
connectPoll: function(self: Provider, request: any): (any?, string?)

Returns the completed stream, nil while pending, or nil and an error.

Arguments
NameTypeDescription
selfProvider
requestany
Returns
TypeDescription
any?
string?
closeConnect#
closeConnect: function(self: Provider, request: any): nil

Releases the connection request, independently of any resulting stream.

Arguments
NameTypeDescription
selfProvider
requestany
Returns
TypeDescription
nil
read#
read: function(self: Provider, stream: any, wanted: integer): (string?, string?)

Returns up to wanted bytes; an empty string means no bytes are ready. Use ended to distinguish EOF. nil with an error reports a failed read.

Arguments
NameTypeDescription
selfProvider
streamany
wantedinteger
Returns
TypeDescription
string?
string?
ended#
ended: function(self: Provider, stream: any): boolean

Reports that no further read bytes will arrive.

Arguments
NameTypeDescription
selfProvider
streamany
Returns
TypeDescription
boolean
write#
write: function(self: Provider, stream: any, bytes: string): (integer?, string?)

Returns the accepted byte count, or nil and an error. Accepted bytes may remain queued; pending reports their outstanding count.

Arguments
NameTypeDescription
selfProvider
streamany
bytesstring
Returns
TypeDescription
integer?
string?
pending#
pending: function(self: Provider, stream: any): integer

Returns bytes accepted for writing that have not yet drained.

Arguments
NameTypeDescription
selfProvider
streamany
Returns
TypeDescription
integer
writeFailed#
writeFailed: function(self: Provider, stream: any): boolean

Reports a terminal write failure, including one after enqueueing.

Arguments
NameTypeDescription
selfProvider
streamany
Returns
TypeDescription
boolean
shuttingDown#
shuttingDown: function(self: Provider, stream: any): boolean

Reports that the sending half is shutting down.

Arguments
NameTypeDescription
selfProvider
streamany
Returns
TypeDescription
boolean
shutdownWrite#
shutdownWrite: function(self: Provider, stream: any): (boolean, string?)

Ends the sending half after queued writes; reports success or an error.

Arguments
NameTypeDescription
selfProvider
streamany
Returns
TypeDescription
boolean
string?
address#
address: function(self: Provider, stream: any, peer: boolean): Address?

Returns the canonical peer or local Address, or nil when unavailable.

Arguments
NameTypeDescription
selfProvider
streamany
peerboolean
Returns
TypeDescription
Address?
noDelay#
noDelay: function(self: Provider, stream: any, enable: boolean): (boolean, string?)

Sets TCP no-delay behavior on a stream.

Arguments
NameTypeDescription
selfProvider
streamany
enableboolean
Returns
TypeDescription
boolean
string?
keepAlive#
keepAlive: function(
    self: Provider,
    stream: any,
    enable: boolean,
    delaySeconds: integer
): (boolean, string?)

Configures TCP keepalive and its idle delay in seconds.

Arguments
NameTypeDescription
selfProvider
streamany
enableboolean
delaySecondsinteger
Returns
TypeDescription
boolean
string?
broadcast#
broadcast: function(self: Provider, socket: any, enable: boolean): (boolean, string?)

Enables or disables sending broadcast datagrams.

Arguments
NameTypeDescription
selfProvider
socketany
enableboolean
Returns
TypeDescription
boolean
string?
multicastTtl#
multicastTtl: function(self: Provider, socket: any, ttl: integer): (boolean, string?)

Sets the datagram multicast hop limit.

Arguments
NameTypeDescription
selfProvider
socketany
ttlinteger
Returns
TypeDescription
boolean
string?
multicastLoop#
multicastLoop: function(self: Provider, socket: any, enable: boolean): (boolean, string?)

Enables or disables local multicast loopback.

Arguments
NameTypeDescription
selfProvider
socketany
enableboolean
Returns
TypeDescription
boolean
string?
membership#
membership: function(
    self: Provider,
    socket: any,
    group: string,
    interfaceAddress: string,
    join: boolean
): (boolean, string?)

Joins or leaves a multicast group on the named interface. An empty interface address selects the host default.

Arguments
NameTypeDescription
selfProvider
socketany
groupstring
interfaceAddressstring
joinboolean
Returns
TypeDescription
boolean
string?
closeStream#
closeStream: function(self: Provider, stream: any): nil

Releases a stream and its queued native resources.

Arguments
NameTypeDescription
selfProvider
streamany
Returns
TypeDescription
nil
bindDatagram#
bindDatagram: function(self: Provider, host: string, port: integer, reusePort: boolean): (any?, string?)

Creates a bound datagram socket or returns nil and an error.

Arguments
NameTypeDescription
selfProvider
hoststring
portinteger
reusePortboolean
Returns
TypeDescription
any?
string?
datagramPort#
datagramPort: function(self: Provider, socket: any): integer

Returns the bound datagram port, or -1 when unavailable.

Arguments
NameTypeDescription
selfProvider
socketany
Returns
TypeDescription
integer
receive#
receive: function(
    self: Provider,
    socket: any,
    maximum: integer
): (string?, string?, integer?, boolean?, string?)

Returns bytes, source host, source port, truncation flag, and optional error. A nil first result without an error means no datagram is ready.

Arguments
NameTypeDescription
selfProvider
socketany
maximuminteger
Returns
TypeDescription
string?
string?
integer?
boolean?
string?
sendTo#
sendTo: function(
    self: Provider,
    socket: any,
    host: string,
    port: integer,
    bytes: string
): (boolean, string?)

Sends one datagram to the destination or reports an error.

Arguments
NameTypeDescription
selfProvider
socketany
hoststring
portinteger
bytesstring
Returns
TypeDescription
boolean
string?
closeDatagram#
closeDatagram: function(self: Provider, socket: any): nil

Releases a datagram socket.

Arguments
NameTypeDescription
selfProvider
socketany
Returns
TypeDescription
nil
run#
run: function(self: Provider, timeoutMs: integer): nil

Pumps shared reactor readiness for at most timeoutMs milliseconds. A zero timeout performs a nonblocking pass.

Arguments
NameTypeDescription
selfProvider
timeoutMsinteger
Returns
TypeDescription
nil

Values#

servicevariable#

const service: services.Service<Provider>

Canonical host.net API 1 handle; setup selects before the public facade loads.