aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/api/sockets.classes.ts
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-10-25 00:44:25 -0700
committerGravatar GitHub <noreply@github.com> 2022-10-25 00:44:25 -0700
commit02c920f4fd09ddc1a32cb2e92c6f391875415949 (patch)
tree4f524f5ce9d672fadb8740c68cc9b1a8410a714f /src/bun.js/api/sockets.classes.ts
parent1b50ecc52b55df0c00f991c8206d4ced84ad89b8 (diff)
downloadbun-02c920f4fd09ddc1a32cb2e92c6f391875415949.tar.gz
bun-02c920f4fd09ddc1a32cb2e92c6f391875415949.tar.zst
bun-02c920f4fd09ddc1a32cb2e92c6f391875415949.zip
TCP & TLS Socket API (#1374)
* TCP Socket API * Wip * Add snippet for StringDecoder * Rename `close` to `stop`, replace `close` with `end` * Add a tcp echo server test * Some docs * Update README.md * Fix build * Update README.md Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bun.js/api/sockets.classes.ts')
-rw-r--r--src/bun.js/api/sockets.classes.ts130
1 files changed, 130 insertions, 0 deletions
diff --git a/src/bun.js/api/sockets.classes.ts b/src/bun.js/api/sockets.classes.ts
new file mode 100644
index 000000000..0c72d1d8d
--- /dev/null
+++ b/src/bun.js/api/sockets.classes.ts
@@ -0,0 +1,130 @@
+import { define } from "../scripts/class-definitions";
+
+function generate(ssl) {
+ return define({
+ name: ssl ? "TCPSocket" : "TLSSocket",
+ JSType: "0b11101110",
+ proto: {
+ write: {
+ fn: "write",
+ length: 3,
+ },
+ end: {
+ fn: "end",
+ length: 3,
+ },
+
+ // },
+ listener: {
+ getter: "getListener",
+ },
+
+ timeout: {
+ fn: "timeout",
+ length: 1,
+ },
+
+ flush: {
+ fn: "flush",
+ length: 0,
+ },
+
+ shutdown: {
+ fn: "shutdown",
+ length: 1,
+ },
+
+ ref: {
+ fn: "ref",
+ length: 0,
+ },
+ unref: {
+ fn: "unref",
+ length: 0,
+ },
+
+ localPort: {
+ getter: "getLocalPort",
+ },
+ // cork: {
+ // fn: "cork",
+ // length: 1,
+ // },
+ data: {
+ getter: "getData",
+ cache: true,
+ setter: "setData",
+ },
+ readyState: {
+ getter: "getReadyState",
+ },
+
+ // topics: {
+ // getter: "getTopics",
+ // },
+
+ remoteAddress: {
+ getter: "getRemoteAddress",
+ cache: true,
+ },
+
+ reload: {
+ fn: "reload",
+ length: 1,
+ },
+ },
+ finalize: true,
+ construct: true,
+ klass: {},
+ });
+}
+export default [
+ generate(true),
+ generate(false),
+ define({
+ name: "Listener",
+ JSType: "0b11101110",
+ proto: {
+ stop: {
+ fn: "stop",
+ length: 1,
+ },
+
+ ref: {
+ fn: "ref",
+ length: 0,
+ },
+ unref: {
+ fn: "unref",
+ length: 0,
+ },
+
+ port: {
+ getter: "getPort",
+ },
+
+ unix: {
+ getter: "getUnix",
+ cache: true,
+ },
+
+ reload: {
+ fn: "reload",
+ length: 1,
+ },
+
+ hostname: {
+ getter: "getHostname",
+ cache: true,
+ },
+
+ data: {
+ getter: "getData",
+ setter: "setData",
+ },
+ },
+ finalize: true,
+ construct: true,
+ klass: {},
+ }),
+];