Skip to content

Latest commit

 

History

History
1227 lines (765 loc) · 47 KB

File metadata and controls

1227 lines (765 loc) · 47 KB

src/minisql/platform/network.ml

Home · Files

Provides minisql platform network facilities for this project.

Package: minisql.platform.network

Reachable from entry: yes

Imports

  • minisql/common/endian.ml as endiansrc/minisql/common/endian.ml
  • std/time.ml as time_api../MiniLangCompilerML/std/time.ml — external dependency

Declarations

_wsaReady

_wsaReady

Stores module-wide wsa ready state for the minisql platform network module.

View source

accept

extern function accept(s as ptr, addr as ptr, addrlen as ptr) from "ws2_32.dll" returns ptr

Accepts one pending connection and returns its socket or INVALID_SOCKET.

Parameter Type Default Description
s ptr s value consumed by this operation.
addr ptr addr value consumed by this operation.
addrlen ptr addrlen value consumed by this operation.

Returns: Native ptr result produced by the call.

View source

acceptTcp

function acceptTcp(listener)

Performs the accept tcp operation for this module. Inputs: listener. Returns the produced value or propagates a structured error from validation or delegated operations.

Parameter Type Default Description
listener dynamic listener value consumed by this operation.

View source

AF_INET

const AF_INET = 2

Defines the af inet constant used by the minisql platform network module.

View source

bind

extern function bind(s as ptr, addr as bytes, addrlen as i32) from "ws2_32.dll" returns i32

Binds socket s to the encoded local address and returns the raw status.

Parameter Type Default Description
s ptr s value consumed by this operation.
addr bytes addr value consumed by this operation.
addrlen i32 addrlen value consumed by this operation.

Returns: Native i32 result produced by the call.

View source

bytePointer

function bytePointer(source, offset, count, operation)

Performs the byte pointer operation for this module. Inputs: source, offset, count, operation. Returns the produced value or propagates a structured error from validation or delegated operations.

Parameter Type Default Description
source dynamic source value consumed by this operation.
offset dynamic Zero-based offset at which processing starts.
count dynamic Number of items or units to process.
operation dynamic operation value consumed by this operation.

View source

cleanup

function cleanup()

Performs the cleanup operation for this module. Takes no caller-supplied inputs. Returns the produced value or propagates a structured error from validation or delegated operations.

View source

close

function close(handle)

Closes close owned by the minisql platform network module. Inputs: handle. Returns the operation result and propagates validation, storage, or platform errors unchanged.

Parameter Type Default Description
handle dynamic Native or runtime handle used by the operation.

View source

closesocket

extern function closesocket(s as ptr) from "ws2_32.dll" returns i32

Closes socket s and returns the raw WinSock status code.

Parameter Type Default Description
s ptr s value consumed by this operation.

Returns: Native i32 result produced by the call.

View source

componentName

function componentName()

Performs the componentName operation for the minisql platform network module. Takes no caller-supplied inputs. Returns the produced value or propagates a structured error from validation or delegated operations.

View source

connect

extern function connect(s as ptr, addr as bytes, addrlen as i32) from "ws2_32.dll" returns i32

Connects socket s to the encoded address and returns the raw WinSock status.

Parameter Type Default Description
s ptr s value consumed by this operation.
addr bytes addr value consumed by this operation.
addrlen i32 addrlen value consumed by this operation.

Returns: Native i32 result produced by the call.

View source

connectTcp

function connectTcp(host, port)

Performs the connect tcp operation for this module. Inputs: host, port. Returns the produced value or propagates a structured error from validation or delegated operations.

Parameter Type Default Description
host dynamic host value consumed by this operation.
port dynamic port value consumed by this operation.

View source

copyByteRange

function copyByteRange(source, offset, count, operation)

Copies the byte range. Inputs: source, offset, count, operation. Returns the produced value or propagates a structured error from validation or delegated operations.

Parameter Type Default Description
source dynamic source value consumed by this operation.
offset dynamic Zero-based offset at which processing starts.
count dynamic Number of items or units to process.
operation dynamic operation value consumed by this operation.

View source

fail

function fail(operation, message)

Performs the fail operation for the minisql platform network module. Inputs: operation, message. Returns the produced value or propagates a structured error from validation or delegated operations.

Parameter Type Default Description
operation dynamic operation value consumed by this operation.
message dynamic Human-readable message associated with the operation.

View source

FIONBIO

const FIONBIO = 2147772030

Defines the fionbio constant used by the minisql platform network module.

View source

getpeername

extern function getpeername(s as ptr, address as bytes, addressLength as bytes) from "ws2_32.dll" returns i32

Reads the connected peer's socket address into a caller-owned sockaddr buffer.

Parameter Type Default Description
s ptr s value consumed by this operation.
address bytes address value consumed by this operation.
addressLength bytes addressLength value consumed by this operation.

Returns: Native i32 result produced by the call.

View source

inet_addr

extern function inet_addr(address as cstr) from "ws2_32.dll" returns u32

Converts a dotted-decimal IPv4 C string to its network-order numeric address.

Parameter Type Default Description
address cstr address value consumed by this operation.

Returns: Native u32 result produced by the call.

View source

initialize

function initialize()

Initializes the requested value. Takes no caller-supplied inputs. Returns the produced value or propagates a structured error from validation or delegated operations.

View source

INVALID_ARGUMENT

const INVALID_ARGUMENT = 9001

Defines the invalid argument constant used by the minisql platform network module.

View source

INVALID_SOCKET

const INVALID_SOCKET = -1

Defines the invalid socket constant used by the minisql platform network module.

View source

ioctlsocket

extern function ioctlsocket(s as ptr, command as u32, value as bytes) from "ws2_32.dll" returns i32

Applies a socket control command using the mutable value buffer and returns raw status.

Parameter Type Default Description
s ptr s value consumed by this operation.
command u32 command value consumed by this operation.
value bytes Value consumed or transformed by the operation.

Returns: Native i32 result produced by the call.

View source

IPPROTO_TCP

const IPPROTO_TCP = 6

Defines the ipproto tcp constant used by the minisql platform network module.

View source

isHandle

function isHandle(value)

Evaluates whether the supplied input satisfies the handle predicate. Inputs: value. Returns a boolean result; invalid input or delegated failures are reported as structured errors.

Parameter Type Default Description
value dynamic Value consumed or transformed by the operation.

View source

isImplemented

function isImplemented()

Returns whether implemented satisfies the condition required by the minisql platform network module. Takes no caller-supplied inputs. Returns a boolean result; invalid input or delegated failures are reported as structured errors.

View source

isLoopbackAddress

function isLoopbackAddress(address)

Evaluates whether the supplied input satisfies the loopback address predicate. Inputs: address. Returns a boolean result; invalid input or delegated failures are reported as structured errors.

Parameter Type Default Description
address dynamic address value consumed by this operation.

View source

isSocketErrorResult

function isSocketErrorResult(value)

WinSock C APIs return a signed 32-bit int. The native ABI writes EAX, so a declaration as a 64-bit MiniLang int can expose SOCKET_ERROR as 0xFFFFFFFF instead of -1. Correct i32 declarations are the primary contract; the dual sentinel check keeps the failure path closed even with an older compiler. Evaluates whether the supplied input satisfies the socket error result predicate. Inputs: value. Returns a boolean result; invalid input or delegated failures are reported as structured errors.

Parameter Type Default Description
value dynamic Value consumed or transformed by the operation.

View source

listen

extern function listen(s as ptr, backlog as i32) from "ws2_32.dll" returns i32

Enables connection acceptance with the requested backlog and returns raw status.

Parameter Type Default Description
s ptr s value consumed by this operation.
backlog i32 backlog value consumed by this operation.

Returns: Native i32 result produced by the call.

View source

listenAddress

function listenAddress(addressText, port, backlog, allowRemote)

Performs the listen address operation for this module. Inputs: addressText, port, backlog, allowRemote. Returns the produced value or propagates a structured error from validation or delegated operations.

Parameter Type Default Description
addressText dynamic addressText value consumed by this operation.
port dynamic port value consumed by this operation.
backlog dynamic backlog value consumed by this operation.
allowRemote dynamic allowRemote value consumed by this operation.

View source

listenLoopback

function listenLoopback(port, backlog)

Performs the listen loopback operation for this module. Inputs: port, backlog. Returns the produced value or propagates a structured error from validation or delegated operations.

Parameter Type Default Description
port dynamic port value consumed by this operation.
backlog dynamic backlog value consumed by this operation.

View source

MAX_RECEIVE_BYTES

const MAX_RECEIVE_BYTES = 16777216

Matches the protocol's exceptional-frame guard. Ordinary polling remains

View source

nativeError

function nativeError()

Returns the current platform socket error using one stable MiniSQL call site.

View source

NETWORK_ERROR

const NETWORK_ERROR = 9026

Native IPv4/TCP wrapper used by MiniSQL clients and servers. M27 adds bounded

View source

parseIPv4

function parseIPv4(host)

Parses the ipv4. Inputs: host. Returns the produced value or propagates a structured error from validation or delegated operations.

Parameter Type Default Description
host dynamic host value consumed by this operation.

View source

peerName

function peerName(handle)

Formats the connected IPv4 peer as address:port for operational logging. Inputs: handle. Returns the peer endpoint or unknown when WinSock cannot expose it.

Parameter Type Default Description
handle dynamic Native or runtime handle used by the operation.

View source

POLLNVAL

const POLLNVAL = 4

Defines the pollnval constant used by the minisql platform network module.

View source

POLLRDNORM

const POLLRDNORM = 256

Defines the pollrdnorm constant used by the minisql platform network module.

View source

POLLWRNORM

const POLLWRNORM = 16

Defines the pollwrnorm constant used by the minisql platform network module.

View source

receive

function receive(handle, maximum)

Performs the receive operation for this module. Inputs: handle, maximum. Returns the produced value or propagates a structured error from validation or delegated operations.

Parameter Type Default Description
handle dynamic Native or runtime handle used by the operation.
maximum dynamic maximum value consumed by this operation.

View source

receiveAvailable

function receiveAvailable(handle, maximum)

Performs the receive available operation for this module. Inputs: handle, maximum. Returns the produced value or propagates a structured error from validation or delegated operations.

Parameter Type Default Description
handle dynamic Native or runtime handle used by the operation.
maximum dynamic maximum value consumed by this operation.

View source

receiveAvailableInto

function receiveAvailableInto(handle, target, offset, maximum)

Performs the receive available into operation for this module. Inputs: handle, target, offset, maximum. Returns the produced value or propagates a structured error from validation or delegated operations.

Parameter Type Default Description
handle dynamic Native or runtime handle used by the operation.
target dynamic target value consumed by this operation.
offset dynamic Zero-based offset at which processing starts.
maximum dynamic maximum value consumed by this operation.

View source

receiveExact

function receiveExact(handle, count)

Performs the receive exact operation for this module. Inputs: handle, count. Returns the produced value or propagates a structured error from validation or delegated operations.

Parameter Type Default Description
handle dynamic Native or runtime handle used by the operation.
count dynamic Number of items or units to process.

View source

recv

extern function recv(s as ptr, buffer as ptr, count as i32, flags as i32) from "ws2_32.dll" returns i32

Receives up to count bytes into buffer and returns count, EOF, or error.

Parameter Type Default Description
s ptr s value consumed by this operation.
buffer ptr Buffer that receives or supplies the operation data.
count i32 Number of items or units to process.
flags i32 Bit flags controlling the operation.

Returns: Native i32 result produced by the call.

View source

SD_BOTH

const SD_BOTH = 2

Defines the sd both constant used by the minisql platform network module.

View source

send

extern function send(s as ptr, buffer as ptr, count as i32, flags as i32) from "ws2_32.dll" returns i32

Sends up to count bytes from buffer and returns the transferred count or error.

Parameter Type Default Description
s ptr s value consumed by this operation.
buffer ptr Buffer that receives or supplies the operation data.
count i32 Number of items or units to process.
flags i32 Bit flags controlling the operation.

Returns: Native i32 result produced by the call.

View source

sendAll

function sendAll(handle, data)

Performs the send all operation for this module. Inputs: handle, data. Returns the produced value or propagates a structured error from validation or delegated operations.

Parameter Type Default Description
handle dynamic Native or runtime handle used by the operation.
data dynamic Input data consumed by the operation.

View source

setNoDelay

function setNoDelay(handle, enabled)

Controls Nagle coalescing on an established TCP stream. MiniSQL exchanges request/response frames synchronously, so delaying a small TLS record until a later packet arrives can add an entire delayed-ACK interval to every query.

Parameter Type Default Description
handle dynamic Native or runtime handle used by the operation.
enabled dynamic enabled value consumed by this operation.

View source

setNonBlocking

function setNonBlocking(handle, enabled)

Updates the non blocking. Inputs: handle, enabled. Returns the operation result and propagates validation, storage, or platform errors unchanged.

Parameter Type Default Description
handle dynamic Native or runtime handle used by the operation.
enabled dynamic enabled value consumed by this operation.

View source

setsockopt

extern function setsockopt(s as ptr, level as i32, option as i32, value as bytes, count as i32) from "ws2_32.dll" returns i32

Sets one socket option from the supplied byte representation and returns raw status.

Parameter Type Default Description
s ptr s value consumed by this operation.
level i32 level value consumed by this operation.
option i32 option value consumed by this operation.
value bytes Value consumed or transformed by the operation.
count i32 Number of items or units to process.

Returns: Native i32 result produced by the call.

View source

setTimeouts

function setTimeouts(handle, receiveMs, sendMs)

Updates the timeouts. Inputs: handle, receiveMs, sendMs. Returns the operation result and propagates validation, storage, or platform errors unchanged.

Parameter Type Default Description
handle dynamic Native or runtime handle used by the operation.
receiveMs dynamic receiveMs value consumed by this operation.
sendMs dynamic sendMs value consumed by this operation.

View source

shutdown

extern function shutdown(s as ptr, how as i32) from "ws2_32.dll" returns i32

Disables the selected socket direction and returns the raw WinSock status.

Parameter Type Default Description
s ptr s value consumed by this operation.
how i32 how value consumed by this operation.

Returns: Native i32 result produced by the call.

View source

sleepMilliseconds

function sleepMilliseconds(milliseconds)

Performs the sleep milliseconds operation for this module. Inputs: milliseconds. Returns the produced value or propagates a structured error from validation or delegated operations.

Parameter Type Default Description
milliseconds dynamic milliseconds value consumed by this operation.

View source

SO_RCVTIMEO

const SO_RCVTIMEO = 4102

Defines the so rcvtimeo constant used by the minisql platform network module.

View source

SO_REUSEADDR

const SO_REUSEADDR = 4

Defines the so reuseaddr constant used by the minisql platform network module.

View source

SO_SNDTIMEO

const SO_SNDTIMEO = 4101

Defines the so sndtimeo constant used by the minisql platform network module.

View source

SOCK_STREAM

const SOCK_STREAM = 1

Defines the sock stream constant used by the minisql platform network module.

View source

sockaddr

function sockaddr(ip, port)

Performs the sockaddr operation for this module. Inputs: ip, port. Returns the produced value or propagates a structured error from validation or delegated operations.

Parameter Type Default Description
ip dynamic ip value consumed by this operation.
port dynamic port value consumed by this operation.

View source

SOCKADDR_IN_SIZE

const SOCKADDR_IN_SIZE = 16

Defines the sockaddr in size constant used by the minisql platform network module.

View source

socket

extern function socket(af as int, type as int, protocol as int) from "ws2_32.dll" returns ptr

Creates a socket for the requested address family, type, and protocol.

Parameter Type Default Description
af int af value consumed by this operation.
type int type value consumed by this operation.
protocol int protocol value consumed by this operation.

Returns: Native ptr result produced by the call.

View source

SOCKET_ERROR

const SOCKET_ERROR = -1

Defines the socket error constant used by the minisql platform network module.

View source

SOCKET_ERROR_U32

const SOCKET_ERROR_U32 = 4294967295

Defines the socket error u32 constant used by the minisql platform network module.

View source

SOL_SOCKET

const SOL_SOCKET = 65535

Defines the sol socket constant used by the minisql platform network module.

View source

targetMilestone

function targetMilestone()

Performs the targetMilestone operation for the minisql platform network module. Takes no caller-supplied inputs. Returns the produced value or propagates a structured error from validation or delegated operations.

View source

TCP_NODELAY

const TCP_NODELAY = 1

Defines the tcp nodelay constant used by the minisql platform network module.

View source

tryAccept

function tryAccept(listener)

Performs the try accept operation for this module. Inputs: listener. Returns the produced value or propagates a structured error from validation or delegated operations.

Parameter Type Default Description
listener dynamic listener value consumed by this operation.

View source

validatePort

function validatePort(port, operation)

Validates the port. Inputs: port, operation. Returns success after all invariants hold; violations are reported as structured errors.

Parameter Type Default Description
port dynamic port value consumed by this operation.
operation dynamic operation value consumed by this operation.

View source

waitReadable

function waitReadable(handle, timeoutMs)

Blocks for at most timeoutMs until recv or accept can make progress.

Parameter Type Default Description
handle dynamic Native or runtime handle used by the operation.
timeoutMs dynamic timeoutMs value consumed by this operation.

View source

waitSocket

function waitSocket(handle, events, timeoutMs, operation)

Waits for one socket event using WinSock's readiness primitive. A timeout is reported as false; readiness, hangup, and socket errors are reported as true so the caller can perform the operation and receive its precise outcome.

Parameter Type Default Description
handle dynamic Native or runtime handle used by the operation.
events dynamic events value consumed by this operation.
timeoutMs dynamic timeoutMs value consumed by this operation.
operation dynamic operation value consumed by this operation.

View source

waitWritable

function waitWritable(handle, timeoutMs)

Blocks for at most timeoutMs until send can make progress.

Parameter Type Default Description
handle dynamic Native or runtime handle used by the operation.
timeoutMs dynamic timeoutMs value consumed by this operation.

View source

WSA_VERSION_2_2

const WSA_VERSION_2_2 = 514

Defines the wsa version 2 2 constant used by the minisql platform network module.

View source

WSACleanup

extern function WSACleanup() from "ws2_32.dll" returns i32

Releases one process-wide WinSock initialization reference and returns its status.

Returns: Native i32 result produced by the call.

View source

WSAEINTR

const WSAEINTR = 10004

Defines the wsaeintr constant used by the minisql platform network module.

View source

WSAETIMEDOUT

const WSAETIMEDOUT = 10060

Defines the wsaetimedout constant used by the minisql platform network module.

View source

WSAEWOULDBLOCK

const WSAEWOULDBLOCK = 10035

Defines the wsaewouldblock constant used by the minisql platform network module.

View source

WSAGetLastError

extern function WSAGetLastError() from "ws2_32.dll" returns i32

Returns the calling thread's most recent WinSock error code.

Returns: Native i32 result produced by the call.

View source

WSAPoll

extern function WSAPoll(descriptors as bytes, descriptorCount as u32, timeoutMs as i32) from "ws2_32.dll" returns i32

Waits until one or more sockets become ready without relying on the Windows timer quantum.

Parameter Type Default Description
descriptors bytes descriptors value consumed by this operation.
descriptorCount u32 Number of descriptor to process.
timeoutMs i32 timeoutMs value consumed by this operation.

Returns: Native i32 result produced by the call.

View source

WSAPOLLFD_EVENTS_OFFSET

const WSAPOLLFD_EVENTS_OFFSET = 8

Defines the wsapollfd events offset constant used by the minisql platform network module.

View source

WSAPOLLFD_REVENTS_OFFSET

const WSAPOLLFD_REVENTS_OFFSET = 10

Defines the wsapollfd revents offset constant used by the minisql platform network module.

View source

WSAPOLLFD_SIZE

const WSAPOLLFD_SIZE = 16

Defines the wsapollfd size constant used by the minisql platform network module.

View source

WSAStartup

extern function WSAStartup(version as int, wsaData as bytes) from "ws2_32.dll" returns i32

Initializes WinSock for version, filling wsaData and returning its status code.

Parameter Type Default Description
version int version value consumed by this operation.
wsaData bytes wsaData value consumed by this operation.

Returns: Native i32 result produced by the call.

View source