Skip to content

Commit

Permalink
feat: add udp-socket-impl method signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
manekinekko committed Oct 30, 2023
1 parent d78ac59 commit 8c40715
Show file tree
Hide file tree
Showing 3 changed files with 223 additions and 26 deletions.
50 changes: 25 additions & 25 deletions packages/preview2-shim/lib/sockets/tcp-socket-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class TcpSocketImpl {
/**
* @param {IpAddressFamily} addressFamily
* @returns
* */
*/
constructor(addressFamily) {

this.#socketOptions.family = addressFamily;
Expand Down Expand Up @@ -175,7 +175,7 @@ export class TcpSocketImpl {
* @throws {invalid-argument} `local-address` is not a unicast address. (EINVAL)
* @throws {invalid-argument} `local-address` is an IPv4-mapped IPv6 address, but the socket has `ipv6-only` enabled. (EINVAL)
* @throws {invalid-state} The socket is already bound. (EINVAL)
* */
*/
startBind(network, localAddress) {
const address = serializeIpAddress(
localAddress,
Expand Down Expand Up @@ -258,7 +258,7 @@ export class TcpSocketImpl {
* @throws {invalid-argument} The socket is already attached to a different network. The `network` passed to `connect` must be identical to the one passed to `bind`.
* @throws {invalid-state} The socket is already in the Connection state. (EISCONN)
* @throws {invalid-state} The socket is already in the Listener state. (EOPNOTSUPP, EINVAL on Windows)
* */
*/
startConnect(network, remoteAddress) {
console.log(
`[tcp] start connect socket to ${remoteAddress.val.address}:${remoteAddress.val.port}`
Expand Down Expand Up @@ -299,7 +299,7 @@ export class TcpSocketImpl {
* @throws {address-in-use} Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD)
* @throws {not-in-progress} A `connect` operation is not in progress.
* @throws {would-block} Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)
* */
*/
finishConnect() {
console.log(`[tcp] finish connect socket`);

Expand Down Expand Up @@ -343,7 +343,7 @@ export class TcpSocketImpl {
* @throws {invalid-state} The socket is not bound to any local address. (EDESTADDRREQ)
* @throws {invalid-state} The socket is already in the Connection state. (EISCONN, EINVAL on BSD)
* @throws {invalid-state} The socket is already in the Listener state.
* */
*/
startListen() {
console.log(
`[tcp] start listen socket on ${this.#socketOptions.localAddress}:${
Expand All @@ -363,7 +363,7 @@ export class TcpSocketImpl {
* @throws {address-in-use} Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE)
* @throws {not-in-progress} A `listen` operation is not in progress.
* @throws {would-block} Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)
* */
*/
finishListen() {
console.log(`[tcp] finish listen socket (backlog: ${this.#backlog})`);

Expand All @@ -385,7 +385,7 @@ export class TcpSocketImpl {
* @throws {would-block} No pending connections at the moment. (EWOULDBLOCK, EAGAIN)
* @throws {connection-aborted} An incoming connection was pending, but was terminated by the client before this listener could accept it. (ECONNABORTED)
* @throws {new-socket-limit} The new socket resource could not be created because of a system limit. (EMFILE, ENFILE)
* */
*/
accept() {
// uv_accept is automatically called by uv_listen when a new connection is received.

Expand All @@ -408,7 +408,7 @@ export class TcpSocketImpl {
/**
* @returns {IpSocketAddress}
* @throws {invalid-state} The socket is not bound to any local address.
* */
*/
localAddress() {
console.log(`[tcp] local address socket`);

Expand All @@ -427,7 +427,7 @@ export class TcpSocketImpl {
/**
* @returns {IpSocketAddress}
* @throws {invalid-state} The socket is not connected to a remote address. (ENOTCONN)
* */
*/
remoteAddress() {
console.log(`[tcp] remote address socket`);

Expand All @@ -438,7 +438,7 @@ export class TcpSocketImpl {

/**
* @returns {IpAddressFamily}
* */
*/
addressFamily() {
console.log(`[tcp] address family socket`);

Expand All @@ -448,7 +448,7 @@ export class TcpSocketImpl {
/**
* @returns {boolean}
* @throws {not-supported} (get/set) `this` socket is an IPv4 socket.
* */
*/
ipv6Only() {
console.log(`[tcp] ipv6 only socket ${this.id}`);

Expand All @@ -461,7 +461,7 @@ export class TcpSocketImpl {
* @throws {invalid-state} (set) The socket is already bound.
* @throws {invalid-state} (get/set) `this` socket is an IPv4 socket.
* @throws {not-supported} (set) Host does not support dual-stack sockets. (Implementations are not required to.)
* */
*/
setIpv6Only(value) {
console.log(`[tcp] set ipv6 only socket to ${value}`);

Expand All @@ -473,7 +473,7 @@ export class TcpSocketImpl {
* @returns {void}
* @throws {not-supported} (set) The platform does not support changing the backlog size after the initial listen.
* @throws {invalid-state} (set) The socket is already in the Connection state.
* */
*/
setListenBacklogSize(value) {
console.log(`[tcp] set listen backlog size socket to ${value}`);

Expand All @@ -482,7 +482,7 @@ export class TcpSocketImpl {

/**
* @returns {boolean}
* */
*/
keepAlive() {
console.log(`[tcp] keep alive socket`);

Expand All @@ -492,7 +492,7 @@ export class TcpSocketImpl {
/**
* @param {boolean} value
* @returns {void}
* */
*/
setKeepAlive(value) {
console.log(`[tcp] set keep alive socket to ${value}`);

Expand All @@ -502,7 +502,7 @@ export class TcpSocketImpl {

/**
* @returns {boolean}
* */
*/
noDelay() {
console.log(`[tcp] no delay socket`);

Expand All @@ -513,7 +513,7 @@ export class TcpSocketImpl {
* @param {boolean} value
* @returns {void}
* @throws {concurrency-conflict} (set) A `bind`, `connect` or `listen` operation is already in progress. (EALREADY)
* */
*/
setNoDelay(value) {
console.log(`[tcp] set no delay socket to ${value}`);

Expand All @@ -523,7 +523,7 @@ export class TcpSocketImpl {

/**
* @returns {number}
* */
*/
unicastHopLimit() {
console.log(`[tcp] unicast hop limit socket`);

Expand All @@ -536,7 +536,7 @@ export class TcpSocketImpl {
* @throws {invalid-argument} (set) The TTL value must be 1 or higher.
* @throws {invalid-state} (set) The socket is already in the Connection state.
* @throws {invalid-state} (set) The socket is already in the Listener state.
* */
*/
setUnicastHopLimit(value) {
console.log(`[tcp] set unicast hop limit socket to ${value}`);

Expand All @@ -545,7 +545,7 @@ export class TcpSocketImpl {

/**
* @returns {bigint}
* */
*/
receiveBufferSize() {
console.log(`[tcp] receive buffer size socket`);
throw new Error("not implemented");
Expand All @@ -556,15 +556,15 @@ export class TcpSocketImpl {
* @returns {void}
* @throws {invalid-state} (set) The socket is already in the Connection state.
* @throws {invalid-state} (set) The socket is already in the Listener state.
* */
*/
setReceiveBufferSize(value) {
console.log(`[tcp] set receive buffer size socket to ${value}`);
throw new Error("not implemented");
}

/**
* @returns {bigint}
* */
*/
sendBufferSize() {
console.log(`[tcp] send buffer size socket`);
throw new Error("not implemented");
Expand All @@ -575,15 +575,15 @@ export class TcpSocketImpl {
* @returns {void}
* @throws {invalid-state} (set) The socket is already in the Connection state.
* @throws {invalid-state} (set) The socket is already in the Listener state.
* */
*/
setSendBufferSize(value) {
console.log(`[tcp] set send buffer size socket to ${value}`);
throw new Error("not implemented");
}

/**
* @returns {Pollable}
* */
*/
subscribe() {
console.log(`[tcp] subscribe socket`);
throw new Error("not implemented");
Expand All @@ -593,7 +593,7 @@ export class TcpSocketImpl {
* @param {ShutdownType} shutdownType
* @returns {void}
* @throws {invalid-state} The socket is not in the Connection state. (ENOTCONN)
* */
*/
shutdown(shutdownType) {
console.log(`[tcp] shutdown socket with type ${shutdownType}`);

Expand Down
161 changes: 161 additions & 0 deletions packages/preview2-shim/lib/sockets/udp-socket-impl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/* eslint-disable no-unused-vars */

/**
* @typedef {import("../../types/interfaces/wasi-sockets-network").Network} Network
* @typedef {import("../../types/interfaces/wasi-sockets-network").IpSocketAddress} IpSocketAddress
* @typedef {import("../../types/interfaces/wasi-sockets-network").IpAddressFamily} IpAddressFamily
* @typedef {import("../../types/interfaces/wasi-sockets-udp").Datagram} Datagram
* @typedef {import("../../types/interfaces/wasi-io-poll-poll").Pollable} Pollable
*/

export class UdpSocketImpl {
/**
*
* @param {Network} network
* @param {IpAddressFamily} localAddress
* @returns {void}
*/
startBind(network, localAddress) {
throw new Error("Not implemented");
}

/**
*
* @returns {void}
*/
finishBind() {
throw new Error("Not implemented");
}

/**
*
* @param {Network} network
* @param {IpAddressFamily} remoteAddress
* @returns {void}
*/
startConnect(network, remoteAddress) {
throw new Error("Not implemented");
}

/**
*
* @returns {void}
*/
finishConnect() {
throw new Error("Not implemented");
}

/**
* @param {bigint} maxResults
* @returns {Datagram[]}
*/
receive(maxResults) {
throw new Error("Not implemented");
}

/**
* @param {Datagram[]} datagrams
* @returns {bigint}
*/
send(datagrams) {
throw new Error("Not implemented");
}

/**
*
* @returns {IpSocketAddress}
*/
localAddress() {
throw new Error("Not implemented");
}

/**
*
* @returns {IpSocketAddress}
*/
remoteAddress() {
throw new Error("Not implemented");
}

/**
*
* @returns {IpAddressFamily}
*/
addressFamily() {
throw new Error("Not implemented");
}

/**
*
* @returns {boolean}
*/
ipv6Only() {
throw new Error("Not implemented");
}

/**
*
* @param {boolean} value
* @returns {void}
*/
setIpv6Only(value) {
throw new Error("Not implemented");
}

/**
*
* @returns {number}
*/
unicastHopLimit() {}

/**
*
* @param {number} value
* @returns {void}
*/
setUnicastHopLimit(value) {
throw new Error("Not implemented");
}

/**
*
* @returns {bigint}
*/
receiveBufferSize() {
throw new Error("Not implemented");
}

/**
*
* @param {bigint} value
* @returns {void}
*/
setReceiveBufferSize(value) {
throw new Error("Not implemented");
}

/**
*
* @returns {bigint}
*/
sendBufferSize() {
throw new Error("Not implemented");
}

/**
*
* @param {bigint} value
* @returns {void}
*/
setSendBufferSize(value) {
throw new Error("Not implemented");
}

/**
*
* @returns {Pollable}
*/
subscribe() {
throw new Error("Not implemented");
}
}
Loading

0 comments on commit 8c40715

Please sign in to comment.