Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bend2/effs/tcp_connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
// The socket is non-blocking for life: EINPROGRESS parks the computation
// until the socket is writable, and then SO_ERROR says how the connect ended.
function tcp_connect(host, port, k) {
const sys = io_sys();
const at = io_addr(host, Number(port));
if (at === null) {
return io_fail(22);
}
const sys = io_sys();
const fd = sys.socket(2, 1, 0);
if (fd < 0) {
return io_fail(sys.errno());
Expand Down
21 changes: 21 additions & 0 deletions tests/io/tcp_connect_no_ffi.bend
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Invalid connect arguments answer EINVAL even when FFI initialization fails.
# The JS twin models a host without bun:ffi; valid Node TCP stays unsupported.
import Base

def ffi_absent() -> IO(Unit):
import "./tcp_connect_no_ffi.js"

def report(r: Result<&1, &1, U32 & String, Socket>) -> IO(Unit):
match r:
case Done{socket}:
Socket.close(socket)
case Fail{(code, message)}:
IO.print(U32.show(code))

def main() -> IO(Unit):
do IO<Unit>:
ffi_absent()
r : Result<&1, &1, U32 & String, Socket> <- TCP.connect("127.0.0.256", 0)
report(r)

#|22
18 changes: 18 additions & 0 deletions tests/io/tcp_connect_no_ffi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Make io_sys initialization fail once, as on a host without bun:ffi.
function ffi_absent_run() {
const prior = Object.getOwnPropertyDescriptor(globalThis, "BEND_SYS");
Object.defineProperty(globalThis, "BEND_SYS", {
configurable: true,
get() {
if (prior) {
Object.defineProperty(globalThis, "BEND_SYS", prior);
} else {
delete globalThis.BEND_SYS;
}
throw new Error("no ffi on this host");
},
});
return { $: CID(Unit) };
}

io_eff(CID(ffi_absent), ffi_absent_run);