mirror of
https://github.com/denoland/deno.git
synced 2025-01-03 12:58:54 -05:00
Rename fd to rid
This commit is contained in:
parent
7cc9b64ff7
commit
c99207bf39
3 changed files with 27 additions and 27 deletions
24
js/files.ts
24
js/files.ts
|
@ -7,18 +7,18 @@ import { assert } from "./util";
|
|||
import { flatbuffers } from "flatbuffers";
|
||||
|
||||
export class File implements Reader, Writer, Closer {
|
||||
constructor(readonly fd: number) {}
|
||||
constructor(readonly rid: number) {}
|
||||
|
||||
write(p: ArrayBufferView): Promise<number> {
|
||||
return write(this.fd, p);
|
||||
return write(this.rid, p);
|
||||
}
|
||||
|
||||
read(p: ArrayBufferView): Promise<ReadResult> {
|
||||
return read(this.fd, p);
|
||||
return read(this.rid, p);
|
||||
}
|
||||
|
||||
close(): void {
|
||||
close(this.fd);
|
||||
close(this.rid);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,17 +47,17 @@ export async function open(
|
|||
assert(msg.Any.OpenRes === baseRes!.innerType());
|
||||
const res = new msg.OpenRes();
|
||||
assert(baseRes!.inner(res) != null);
|
||||
const fd = res.rid();
|
||||
return new File(fd);
|
||||
const rid = res.rid();
|
||||
return new File(rid);
|
||||
}
|
||||
|
||||
export async function read(
|
||||
fd: number,
|
||||
rid: number,
|
||||
p: ArrayBufferView
|
||||
): Promise<ReadResult> {
|
||||
const builder = new flatbuffers.Builder();
|
||||
msg.Read.startRead(builder);
|
||||
msg.Read.addRid(builder, fd);
|
||||
msg.Read.addRid(builder, rid);
|
||||
const inner = msg.Read.endRead(builder);
|
||||
const baseRes = await dispatch.sendAsync(builder, msg.Any.Read, inner, p);
|
||||
assert(baseRes != null);
|
||||
|
@ -67,10 +67,10 @@ export async function read(
|
|||
return { nread: res.nread(), eof: res.eof() };
|
||||
}
|
||||
|
||||
export async function write(fd: number, p: ArrayBufferView): Promise<number> {
|
||||
export async function write(rid: number, p: ArrayBufferView): Promise<number> {
|
||||
const builder = new flatbuffers.Builder();
|
||||
msg.Write.startWrite(builder);
|
||||
msg.Write.addRid(builder, fd);
|
||||
msg.Write.addRid(builder, rid);
|
||||
const inner = msg.Write.endWrite(builder);
|
||||
const baseRes = await dispatch.sendAsync(builder, msg.Any.Write, inner, p);
|
||||
assert(baseRes != null);
|
||||
|
@ -80,10 +80,10 @@ export async function write(fd: number, p: ArrayBufferView): Promise<number> {
|
|||
return res.nbyte();
|
||||
}
|
||||
|
||||
export function close(fd: number): void {
|
||||
export function close(rid: number): void {
|
||||
const builder = new flatbuffers.Builder();
|
||||
msg.Close.startClose(builder);
|
||||
msg.Close.addRid(builder, fd);
|
||||
msg.Close.addRid(builder, rid);
|
||||
const inner = msg.Close.endClose(builder);
|
||||
dispatch.sendSync(builder, msg.Any.Close, inner);
|
||||
}
|
||||
|
|
|
@ -4,15 +4,15 @@ import * as deno from "deno";
|
|||
import { test, assert, assertEqual } from "./test_util.ts";
|
||||
|
||||
test(function filesStdioFileDescriptors() {
|
||||
assertEqual(deno.stdin.fd, 0);
|
||||
assertEqual(deno.stdout.fd, 1);
|
||||
assertEqual(deno.stderr.fd, 2);
|
||||
assertEqual(deno.stdin.rid, 0);
|
||||
assertEqual(deno.stdout.rid, 1);
|
||||
assertEqual(deno.stderr.rid, 2);
|
||||
});
|
||||
|
||||
test(async function filesCopyToStdout() {
|
||||
const filename = "package.json";
|
||||
const file = await deno.open(filename);
|
||||
assert(file.fd > 2);
|
||||
assert(file.rid > 2);
|
||||
const bytesWritten = await deno.copy(deno.stdout, file);
|
||||
const fileSize = deno.statSync(filename).len;
|
||||
assertEqual(bytesWritten, fileSize);
|
||||
|
|
22
js/net.ts
22
js/net.ts
|
@ -28,12 +28,12 @@ export interface Listener {
|
|||
}
|
||||
|
||||
class ListenerImpl implements Listener {
|
||||
constructor(readonly fd: number) {}
|
||||
constructor(readonly rid: number) {}
|
||||
|
||||
async accept(): Promise<Conn> {
|
||||
const builder = new flatbuffers.Builder();
|
||||
msg.Accept.startAccept(builder);
|
||||
msg.Accept.addRid(builder, this.fd);
|
||||
msg.Accept.addRid(builder, this.rid);
|
||||
const inner = msg.Accept.endAccept(builder);
|
||||
const baseRes = await dispatch.sendAsync(builder, msg.Any.Accept, inner);
|
||||
assert(baseRes != null);
|
||||
|
@ -44,7 +44,7 @@ class ListenerImpl implements Listener {
|
|||
}
|
||||
|
||||
close(): void {
|
||||
close(this.fd);
|
||||
close(this.rid);
|
||||
}
|
||||
|
||||
addr(): Addr {
|
||||
|
@ -61,35 +61,35 @@ export interface Conn extends Reader, Writer, Closer {
|
|||
|
||||
class ConnImpl implements Conn {
|
||||
constructor(
|
||||
readonly fd: number,
|
||||
readonly rid: number,
|
||||
readonly remoteAddr: string,
|
||||
readonly localAddr: string
|
||||
) {}
|
||||
|
||||
write(p: ArrayBufferView): Promise<number> {
|
||||
return write(this.fd, p);
|
||||
return write(this.rid, p);
|
||||
}
|
||||
|
||||
read(p: ArrayBufferView): Promise<ReadResult> {
|
||||
return read(this.fd, p);
|
||||
return read(this.rid, p);
|
||||
}
|
||||
|
||||
close(): void {
|
||||
close(this.fd);
|
||||
close(this.rid);
|
||||
}
|
||||
|
||||
/** closeRead shuts down (shutdown(2)) the reading side of the TCP connection.
|
||||
* Most callers should just use close().
|
||||
*/
|
||||
closeRead(): void {
|
||||
shutdown(this.fd, ShutdownMode.Read);
|
||||
shutdown(this.rid, ShutdownMode.Read);
|
||||
}
|
||||
|
||||
/** closeWrite shuts down (shutdown(2)) the writing side of the TCP
|
||||
* connection. Most callers should just use close().
|
||||
*/
|
||||
closeWrite(): void {
|
||||
shutdown(this.fd, ShutdownMode.Write);
|
||||
shutdown(this.rid, ShutdownMode.Write);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,10 +101,10 @@ enum ShutdownMode {
|
|||
ReadWrite // unused
|
||||
}
|
||||
|
||||
function shutdown(fd: number, how: ShutdownMode) {
|
||||
function shutdown(rid: number, how: ShutdownMode) {
|
||||
const builder = new flatbuffers.Builder();
|
||||
msg.Shutdown.startShutdown(builder);
|
||||
msg.Shutdown.addRid(builder, fd);
|
||||
msg.Shutdown.addRid(builder, rid);
|
||||
msg.Shutdown.addHow(builder, how);
|
||||
const inner = msg.Shutdown.endShutdown(builder);
|
||||
const baseRes = dispatch.sendSync(builder, msg.Any.Shutdown, inner);
|
||||
|
|
Loading…
Reference in a new issue