-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b39d2c
commit 946acbc
Showing
9 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2018 the Deno authors. All rights reserved. MIT license. | ||
import * as msg from "gen/msg_generated"; | ||
import * as flatbuffers from "./flatbuffers"; | ||
import { assert } from "./util"; | ||
import * as dispatch from "./dispatch"; | ||
|
||
export function resources(): { [key: number]: string } { | ||
const builder = flatbuffers.createBuilder(); | ||
msg.Resources.startResources(builder); | ||
const inner = msg.Resource.endResource(builder); | ||
const baseRes = dispatch.sendSync(builder, msg.Any.Resources, inner); | ||
assert(baseRes !== null); | ||
assert(msg.Any.ResourcesRes === baseRes!.innerType()); | ||
const res = new msg.ResourcesRes(); | ||
assert(baseRes!.inner(res) !== null); | ||
|
||
const resources: { [key: number]: string } = {}; | ||
|
||
for (let i = 0; i < res.resourcesLength(); i++) { | ||
const item = res.resources(i)!; | ||
resources[item.rid()!] = item.repr()!; | ||
} | ||
|
||
return resources; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2018 the Deno authors. All rights reserved. MIT license. | ||
import { test, testPerm, assert, assertEqual } from "./test_util.ts"; | ||
import * as deno from "deno"; | ||
|
||
test(function resourcesStdio() { | ||
const res = deno.resources(); | ||
|
||
assertEqual(res[0], "stdin"); | ||
assertEqual(res[1], "stdout"); | ||
assertEqual(res[2], "stderr"); | ||
}); | ||
|
||
testPerm({ net: true }, async function resourcesNet() { | ||
const addr = "127.0.0.1:4501"; | ||
const listener = deno.listen("tcp", addr); | ||
|
||
const dialerConn = await deno.dial("tcp", addr); | ||
const listenerConn = await listener.accept(); | ||
|
||
const res = deno.resources(); | ||
assertEqual(Object.values(res).filter(r => r === "tcpListener").length, 1); | ||
assertEqual(Object.values(res).filter(r => r === "tcpStream").length, 2); | ||
|
||
listenerConn.close(); | ||
dialerConn.close(); | ||
listener.close(); | ||
}); | ||
|
||
test(async function resourcesFile() { | ||
const resourcesBefore = deno.resources(); | ||
await deno.open("tests/hello.txt"); | ||
const resourcesAfter = deno.resources(); | ||
|
||
// check that exactly one new resource (file) was added | ||
assertEqual( | ||
Object.keys(resourcesAfter).length, | ||
Object.keys(resourcesBefore).length + 1 | ||
); | ||
const newRid = Object.keys(resourcesAfter).find(rid => { | ||
return !resourcesBefore.hasOwnProperty(rid); | ||
}); | ||
assertEqual(resourcesAfter[newRid], "fsFile"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello world! |