@bytecodealliance/preview2-shim 0.22.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,6 @@
1
1
  import { createFuture, createReadableStream, createReadableStreamPollState, createWritableStream, futureDispose, futureTakeValue, pollStateReady, verifyPollsDroppedForDrop, } from "./worker-thread.js";
2
- import process from "node:process";
3
2
  import { convertSocketError, ipSocketAddress, isIPv4MappedAddress, isMulticastIpAddress, isUnicastIpAddress, isWildcardAddress, noLookup, serializeIpAddress, SOCKET_STATE_BIND, SOCKET_STATE_BOUND, SOCKET_STATE_CLOSED, SOCKET_STATE_CONNECT, SOCKET_STATE_CONNECTION, SOCKET_STATE_INIT, SOCKET_STATE_LISTEN, SOCKET_STATE_LISTENER, } from "./worker-sockets.js";
4
3
  import { Server, Socket as TcpSocket } from "node:net";
5
- const win = process.platform === "win32";
6
4
  export const tcpSockets = new Map();
7
5
  let tcpSocketCnt = 0;
8
6
  export function createTcpSocket() {
@@ -37,7 +35,16 @@ export function socketTcpFinish(id, fromState, toState) {
37
35
  futureDispose(socket.future, false);
38
36
  socket.future = null;
39
37
  if (tag === "err") {
40
- socket.state = SOCKET_STATE_CLOSED;
38
+ // A failed bind does not consume the socket. In particular, callers may
39
+ // retry after `address-in-use` with another address or port.
40
+ if (fromState === SOCKET_STATE_BIND) {
41
+ socket.server = null;
42
+ socket.localAddress = null;
43
+ socket.state = SOCKET_STATE_INIT;
44
+ }
45
+ else {
46
+ socket.state = SOCKET_STATE_CLOSED;
47
+ }
41
48
  throw val;
42
49
  }
43
50
  else {
@@ -255,12 +262,7 @@ export function socketTcpShutdown(id, _shutdownType) {
255
262
  if (socket.state !== SOCKET_STATE_CONNECTION) {
256
263
  throw "invalid-state";
257
264
  }
258
- if (win && socket.tcpSocket?.destroySoon) {
259
- socket.tcpSocket.destroySoon();
260
- }
261
- else {
262
- socket.tcpSocket?.destroy();
263
- }
265
+ socket.tcpSocket?.destroy();
264
266
  }
265
267
  export function socketTcpSetKeepAlive(id, { keepAlive, keepAliveIdleTime }) {
266
268
  const socket = tcpSockets.get(id);
@@ -727,7 +727,6 @@ async function getDefaultReceiveBufferSize() {
727
727
  }
728
728
  //#endregion
729
729
  //#region dist/io/worker-socket-tcp.js
730
- const win = process.platform === "win32";
731
730
  const tcpSockets = /* @__PURE__ */ new Map();
732
731
  let tcpSocketCnt = 0;
733
732
  function createTcpSocket() {
@@ -758,7 +757,11 @@ function socketTcpFinish(id, fromState, toState) {
758
757
  futureDispose(socket.future, false);
759
758
  socket.future = null;
760
759
  if (tag === "err") {
761
- socket.state = SOCKET_STATE_CLOSED;
760
+ if (fromState === SOCKET_STATE_BIND) {
761
+ socket.server = null;
762
+ socket.localAddress = null;
763
+ socket.state = SOCKET_STATE_INIT;
764
+ } else socket.state = SOCKET_STATE_CLOSED;
762
765
  throw val;
763
766
  } else {
764
767
  socket.state = toState;
@@ -924,8 +927,7 @@ function socketTcpGetRemoteAddress(id) {
924
927
  function socketTcpShutdown(id, _shutdownType) {
925
928
  const socket = tcpSockets.get(id);
926
929
  if (socket.state !== SOCKET_STATE_CONNECTION) throw "invalid-state";
927
- if (win && socket.tcpSocket?.destroySoon) socket.tcpSocket.destroySoon();
928
- else socket.tcpSocket?.destroy();
930
+ socket.tcpSocket?.destroy();
929
931
  }
930
932
  function socketTcpSetKeepAlive(id, { keepAlive, keepAliveIdleTime }) {
931
933
  const socket = tcpSockets.get(id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytecodealliance/preview2-shim",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "description": "WASI Preview2 shim for JS environments",
5
5
  "homepage": "https://github.com/bytecodealliance/jco#readme",
6
6
  "bugs": {