/
githubmirror
/
deno
Обзор
Документация
Войти
/
githubmirror
/
deno
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
tests/specs/node/pipe_open_fd/main_write.ts
40 строк
1 KB
Bartek Iwańczuk
fix(ext/node): create net.Socket from file descriptors (#33150)
03 апр 2026, 12:47
Не верифицирован
03 апр 2026, 12:47
4e6eb1e
Код
Авторство
О чём код?
// Test Pipe.open(fd) for writing via net.Socket({ fd }). import { createRequire } from "node:module"; const require = createRequire(import.meta.url); const fs = require("fs"); const net = require("net"); const path = require("path"); const os = require("os"); const tmpFile = path.join( os.tmpdir(), `deno_pipe_write_test_${process.pid}.txt`, ); // Create a pipe (FIFO) to get a PIPE-type fd, or just use a socketpair. // Simplest: write to a file via child process using inherited fd. // Actually, the simplest test: create a unix socket server, connect, // and verify data flows through a socket fd wrapped in net.Socket. const sockPath = path.join(os.tmpdir(), `deno_pipe_write_${process.pid}.sock`); try { fs.unlinkSync(sockPath); } catch {} const server = net.createServer((conn: any) => { let data = ""; conn.on("data", (chunk: any) => data += chunk); conn.on("end", () => { console.log("server received:", data.trim()); server.close(); try { fs.unlinkSync(sockPath); } catch {} }); }); server.listen(sockPath, () => { const client = net.connect(sockPath, () => { client.write("hello from pipe write\n"); client.end(); }); });