Skip to content

Commit

Permalink
node:net: stub out [get|set]DefaultAutoSelectFamily[AttemptTimeout] (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nektro authored Apr 26, 2024
1 parent b257a30 commit 181d6a0
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/runtime/nodejs-apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Some methods are not optimized yet.

### [`node:net`](https://nodejs.org/api/net.html)

🟡 Missing `BlockList` `SocketAddress` `Stream` `getDefaultAutoSelectFamily` `getDefaultAutoSelectFamilyAttemptTimeout` `setDefaultAutoSelectFamily` `setDefaultAutoSelectFamilyAttemptTimeout`
🟡 Missing `BlockList` `SocketAddress` `Stream`

### [`node:os`](https://nodejs.org/api/os.html)

Expand Down
77 changes: 77 additions & 0 deletions src/bun.js/node/node_net_binding.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
const std = @import("std");
const bun = @import("root").bun;
const Environment = bun.Environment;
const JSC = bun.JSC;
const string = bun.string;
const Output = bun.Output;
const ZigString = JSC.ZigString;

//
//

pub var autoSelectFamilyDefault: bool = true;

pub fn getDefaultAutoSelectFamily(global: *JSC.JSGlobalObject) callconv(.C) JSC.JSValue {
return JSC.JSFunction.create(global, "getDefaultAutoSelectFamily", (struct {
fn getter(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) callconv(.C) JSC.JSValue {
_ = globalThis;
_ = callframe;
return JSC.jsBoolean(autoSelectFamilyDefault);
}
}).getter, 0, .{});
}

pub fn setDefaultAutoSelectFamily(global: *JSC.JSGlobalObject) callconv(.C) JSC.JSValue {
return JSC.JSFunction.create(global, "setDefaultAutoSelectFamily", (struct {
fn setter(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) callconv(.C) JSC.JSValue {
const arguments = callframe.arguments(1);
if (arguments.len < 1) {
globalThis.throw("missing argument", .{});
return .undefined;
}
const arg = arguments.slice()[0];
if (!arg.isBoolean()) {
globalThis.throwInvalidArguments("autoSelectFamilyDefault", .{});
return .undefined;
}
const value = arg.toBoolean();
autoSelectFamilyDefault = value;
return JSC.jsBoolean(value);
}
}).setter, 1, .{});
}

//
//

pub var autoSelectFamilyAttemptTimeoutDefault: u32 = 250;

pub fn getDefaultAutoSelectFamilyAttemptTimeout(global: *JSC.JSGlobalObject) callconv(.C) JSC.JSValue {
return JSC.JSFunction.create(global, "getDefaultAutoSelectFamilyAttemptTimeout", (struct {
fn getter(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) callconv(.C) JSC.JSValue {
_ = globalThis;
_ = callframe;
return JSC.jsNumber(autoSelectFamilyAttemptTimeoutDefault);
}
}).getter, 0, .{});
}

pub fn setDefaultAutoSelectFamilyAttemptTimeout(global: *JSC.JSGlobalObject) callconv(.C) JSC.JSValue {
return JSC.JSFunction.create(global, "setDefaultAutoSelectFamilyAttemptTimeout", (struct {
fn setter(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) callconv(.C) JSC.JSValue {
const arguments = callframe.arguments(1);
if (arguments.len < 1) {
globalThis.throw("missing argument", .{});
return .undefined;
}
const arg = arguments.slice()[0];
if (!arg.isInt32AsAnyInt()) {
globalThis.throwInvalidArguments("autoSelectFamilyAttemptTimeoutDefault", .{});
return .undefined;
}
const value: u32 = @max(10, arg.coerceToInt32(globalThis));
autoSelectFamilyAttemptTimeoutDefault = value;
return JSC.jsNumber(value);
}
}).setter, 1, .{});
}
5 changes: 5 additions & 0 deletions src/js/node/net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -990,4 +990,9 @@ export default {
isIPv6,
Socket,
[Symbol.for("::bunternal::")]: SocketClass,

getDefaultAutoSelectFamily: $zig("node_net_binding.zig", "getDefaultAutoSelectFamily"),
setDefaultAutoSelectFamily: $zig("node_net_binding.zig", "setDefaultAutoSelectFamily"),
getDefaultAutoSelectFamilyAttemptTimeout: $zig("node_net_binding.zig", "getDefaultAutoSelectFamilyAttemptTimeout"),
setDefaultAutoSelectFamilyAttemptTimeout: $zig("node_net_binding.zig", "setDefaultAutoSelectFamilyAttemptTimeout"),
};

0 comments on commit 181d6a0

Please sign in to comment.