@fuman/bun 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +8 -0
- package/connection.cjs +112 -0
- package/connection.d.ts +20 -0
- package/connection.js +112 -0
- package/functions.cjs +31 -0
- package/functions.d.ts +5 -0
- package/functions.js +31 -0
- package/index.cjs +10 -0
- package/index.d.ts +3 -0
- package/index.js +10 -0
- package/listener.cjs +61 -0
- package/listener.d.ts +10 -0
- package/listener.js +61 -0
- package/package.json +31 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Copyright 2024 alina sireneva
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
8
|
+
|
package/connection.cjs
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const io = require("@fuman/io");
|
|
4
|
+
const net = require("@fuman/net");
|
|
5
|
+
const utils = require("@fuman/utils");
|
|
6
|
+
class TcpConnection {
|
|
7
|
+
socket;
|
|
8
|
+
#error = null;
|
|
9
|
+
#recvBuffer = io.Bytes.alloc(1024 * 16);
|
|
10
|
+
#sendBuffer = new utils.Deque();
|
|
11
|
+
#cv = new utils.ConditionVariable();
|
|
12
|
+
#endpoint;
|
|
13
|
+
async connect(endpoint, tls = false) {
|
|
14
|
+
this.socket = await Bun.connect({
|
|
15
|
+
hostname: endpoint.address,
|
|
16
|
+
port: endpoint.port,
|
|
17
|
+
socket: {
|
|
18
|
+
data: this._handleData.bind(this),
|
|
19
|
+
error: this._handleError.bind(this),
|
|
20
|
+
close: this._handleClose.bind(this),
|
|
21
|
+
drain: this._handleDrain.bind(this)
|
|
22
|
+
},
|
|
23
|
+
tls
|
|
24
|
+
});
|
|
25
|
+
this.#endpoint = endpoint;
|
|
26
|
+
}
|
|
27
|
+
static from(socket) {
|
|
28
|
+
const conn = new TcpConnection();
|
|
29
|
+
conn.socket = socket;
|
|
30
|
+
return conn;
|
|
31
|
+
}
|
|
32
|
+
_handleData(_, data) {
|
|
33
|
+
this.#recvBuffer.writeSync(data.length).set(data);
|
|
34
|
+
this.#cv.notify();
|
|
35
|
+
}
|
|
36
|
+
_handleError(_, error) {
|
|
37
|
+
this.#error = error;
|
|
38
|
+
this.#cv.notify();
|
|
39
|
+
}
|
|
40
|
+
_handleClose() {
|
|
41
|
+
this.#error = new net.ConnectionClosedError();
|
|
42
|
+
this.#cv.notify();
|
|
43
|
+
for (const [, deferred] of this.#sendBuffer) {
|
|
44
|
+
deferred.reject(this.#error);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
_handleDrain() {
|
|
48
|
+
while (!this.#sendBuffer.isEmpty()) {
|
|
49
|
+
const [chunk, deferred] = this.#sendBuffer.popFront();
|
|
50
|
+
const written = this.socket.write(chunk);
|
|
51
|
+
if (written < chunk.length) {
|
|
52
|
+
this.#sendBuffer.pushFront([chunk.subarray(written), deferred]);
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
deferred.resolve();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async read(into) {
|
|
59
|
+
if (this.#recvBuffer.available > 0) {
|
|
60
|
+
const size2 = Math.min(this.#recvBuffer.available, into.length);
|
|
61
|
+
into.set(this.#recvBuffer.readSync(size2));
|
|
62
|
+
this.#recvBuffer.reclaim();
|
|
63
|
+
return size2;
|
|
64
|
+
}
|
|
65
|
+
if (this.#error != null) throw this.#error;
|
|
66
|
+
await this.#cv.wait();
|
|
67
|
+
if (this.#error != null) throw this.#error;
|
|
68
|
+
const size = Math.min(this.#recvBuffer.available, into.length);
|
|
69
|
+
into.set(this.#recvBuffer.readSync(size));
|
|
70
|
+
this.#recvBuffer.reclaim();
|
|
71
|
+
return size;
|
|
72
|
+
}
|
|
73
|
+
async write(bytes) {
|
|
74
|
+
if (this.#error) throw this.#error;
|
|
75
|
+
const written = this.socket.write(bytes);
|
|
76
|
+
if (written < bytes.length) {
|
|
77
|
+
const deferred = new utils.Deferred();
|
|
78
|
+
this.#sendBuffer.pushBack([bytes.subarray(written), deferred]);
|
|
79
|
+
return deferred.promise;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
close() {
|
|
83
|
+
this.socket.end();
|
|
84
|
+
this._handleClose();
|
|
85
|
+
}
|
|
86
|
+
get localAddress() {
|
|
87
|
+
const isIpv6 = this.socket.remoteAddress.includes(":");
|
|
88
|
+
return {
|
|
89
|
+
address: isIpv6 ? "::1" : "127.0.0.1",
|
|
90
|
+
port: this.socket.localPort
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
get remoteAddress() {
|
|
94
|
+
if (this.#endpoint) return this.#endpoint;
|
|
95
|
+
return {
|
|
96
|
+
address: this.socket.remoteAddress,
|
|
97
|
+
get port() {
|
|
98
|
+
throw new Error("Not available in Bun");
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
setKeepAlive(_val) {
|
|
103
|
+
throw new Error("Not available in Bun");
|
|
104
|
+
}
|
|
105
|
+
setNoDelay(_val) {
|
|
106
|
+
throw new Error("Not available in Bun");
|
|
107
|
+
}
|
|
108
|
+
getAlpnProtocol() {
|
|
109
|
+
throw new Error("Not available in Bun");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.TcpConnection = TcpConnection;
|
package/connection.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ITcpConnection, ITlsConnection, TcpEndpoint } from '@fuman/net';
|
|
2
|
+
import { Socket } from 'bun';
|
|
3
|
+
export declare class TcpConnection implements ITcpConnection, ITlsConnection {
|
|
4
|
+
#private;
|
|
5
|
+
readonly socket: Socket<any>;
|
|
6
|
+
connect(endpoint: TcpEndpoint, tls?: boolean): Promise<void>;
|
|
7
|
+
static from(socket: Socket<any>): TcpConnection;
|
|
8
|
+
_handleData(_: unknown, data: Buffer): void;
|
|
9
|
+
_handleError(_: unknown, error: Error): void;
|
|
10
|
+
_handleClose(): void;
|
|
11
|
+
_handleDrain(): void;
|
|
12
|
+
read(into: Uint8Array): Promise<number>;
|
|
13
|
+
write(bytes: Uint8Array): Promise<void>;
|
|
14
|
+
close(): void;
|
|
15
|
+
get localAddress(): TcpEndpoint;
|
|
16
|
+
get remoteAddress(): TcpEndpoint;
|
|
17
|
+
setKeepAlive(_val: boolean): void;
|
|
18
|
+
setNoDelay(_val: boolean): void;
|
|
19
|
+
getAlpnProtocol(): string | null;
|
|
20
|
+
}
|
package/connection.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Bytes } from "@fuman/io";
|
|
2
|
+
import { ConnectionClosedError } from "@fuman/net";
|
|
3
|
+
import { Deque, ConditionVariable, Deferred } from "@fuman/utils";
|
|
4
|
+
class TcpConnection {
|
|
5
|
+
socket;
|
|
6
|
+
#error = null;
|
|
7
|
+
#recvBuffer = Bytes.alloc(1024 * 16);
|
|
8
|
+
#sendBuffer = new Deque();
|
|
9
|
+
#cv = new ConditionVariable();
|
|
10
|
+
#endpoint;
|
|
11
|
+
async connect(endpoint, tls = false) {
|
|
12
|
+
this.socket = await Bun.connect({
|
|
13
|
+
hostname: endpoint.address,
|
|
14
|
+
port: endpoint.port,
|
|
15
|
+
socket: {
|
|
16
|
+
data: this._handleData.bind(this),
|
|
17
|
+
error: this._handleError.bind(this),
|
|
18
|
+
close: this._handleClose.bind(this),
|
|
19
|
+
drain: this._handleDrain.bind(this)
|
|
20
|
+
},
|
|
21
|
+
tls
|
|
22
|
+
});
|
|
23
|
+
this.#endpoint = endpoint;
|
|
24
|
+
}
|
|
25
|
+
static from(socket) {
|
|
26
|
+
const conn = new TcpConnection();
|
|
27
|
+
conn.socket = socket;
|
|
28
|
+
return conn;
|
|
29
|
+
}
|
|
30
|
+
_handleData(_, data) {
|
|
31
|
+
this.#recvBuffer.writeSync(data.length).set(data);
|
|
32
|
+
this.#cv.notify();
|
|
33
|
+
}
|
|
34
|
+
_handleError(_, error) {
|
|
35
|
+
this.#error = error;
|
|
36
|
+
this.#cv.notify();
|
|
37
|
+
}
|
|
38
|
+
_handleClose() {
|
|
39
|
+
this.#error = new ConnectionClosedError();
|
|
40
|
+
this.#cv.notify();
|
|
41
|
+
for (const [, deferred] of this.#sendBuffer) {
|
|
42
|
+
deferred.reject(this.#error);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
_handleDrain() {
|
|
46
|
+
while (!this.#sendBuffer.isEmpty()) {
|
|
47
|
+
const [chunk, deferred] = this.#sendBuffer.popFront();
|
|
48
|
+
const written = this.socket.write(chunk);
|
|
49
|
+
if (written < chunk.length) {
|
|
50
|
+
this.#sendBuffer.pushFront([chunk.subarray(written), deferred]);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
deferred.resolve();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async read(into) {
|
|
57
|
+
if (this.#recvBuffer.available > 0) {
|
|
58
|
+
const size2 = Math.min(this.#recvBuffer.available, into.length);
|
|
59
|
+
into.set(this.#recvBuffer.readSync(size2));
|
|
60
|
+
this.#recvBuffer.reclaim();
|
|
61
|
+
return size2;
|
|
62
|
+
}
|
|
63
|
+
if (this.#error != null) throw this.#error;
|
|
64
|
+
await this.#cv.wait();
|
|
65
|
+
if (this.#error != null) throw this.#error;
|
|
66
|
+
const size = Math.min(this.#recvBuffer.available, into.length);
|
|
67
|
+
into.set(this.#recvBuffer.readSync(size));
|
|
68
|
+
this.#recvBuffer.reclaim();
|
|
69
|
+
return size;
|
|
70
|
+
}
|
|
71
|
+
async write(bytes) {
|
|
72
|
+
if (this.#error) throw this.#error;
|
|
73
|
+
const written = this.socket.write(bytes);
|
|
74
|
+
if (written < bytes.length) {
|
|
75
|
+
const deferred = new Deferred();
|
|
76
|
+
this.#sendBuffer.pushBack([bytes.subarray(written), deferred]);
|
|
77
|
+
return deferred.promise;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
close() {
|
|
81
|
+
this.socket.end();
|
|
82
|
+
this._handleClose();
|
|
83
|
+
}
|
|
84
|
+
get localAddress() {
|
|
85
|
+
const isIpv6 = this.socket.remoteAddress.includes(":");
|
|
86
|
+
return {
|
|
87
|
+
address: isIpv6 ? "::1" : "127.0.0.1",
|
|
88
|
+
port: this.socket.localPort
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
get remoteAddress() {
|
|
92
|
+
if (this.#endpoint) return this.#endpoint;
|
|
93
|
+
return {
|
|
94
|
+
address: this.socket.remoteAddress,
|
|
95
|
+
get port() {
|
|
96
|
+
throw new Error("Not available in Bun");
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
setKeepAlive(_val) {
|
|
101
|
+
throw new Error("Not available in Bun");
|
|
102
|
+
}
|
|
103
|
+
setNoDelay(_val) {
|
|
104
|
+
throw new Error("Not available in Bun");
|
|
105
|
+
}
|
|
106
|
+
getAlpnProtocol() {
|
|
107
|
+
throw new Error("Not available in Bun");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export {
|
|
111
|
+
TcpConnection
|
|
112
|
+
};
|
package/functions.cjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const connection = require("./connection.cjs");
|
|
4
|
+
const listener = require("./listener.cjs");
|
|
5
|
+
const connectTcp = async (endpoint) => {
|
|
6
|
+
const connection$1 = new connection.TcpConnection();
|
|
7
|
+
await connection$1.connect(endpoint);
|
|
8
|
+
return connection$1;
|
|
9
|
+
};
|
|
10
|
+
const connectTls = async (opts) => {
|
|
11
|
+
if (opts.sni != null) {
|
|
12
|
+
throw new Error(".sni is not available in Bun");
|
|
13
|
+
}
|
|
14
|
+
if (opts.caCerts) {
|
|
15
|
+
throw new Error(".caCerts is not available in Bun");
|
|
16
|
+
}
|
|
17
|
+
if (opts.alpnProtocols) {
|
|
18
|
+
throw new Error(".alpnProtocols is not available in Bun");
|
|
19
|
+
}
|
|
20
|
+
const connection$1 = new connection.TcpConnection();
|
|
21
|
+
await connection$1.connect(opts, true);
|
|
22
|
+
return connection$1;
|
|
23
|
+
};
|
|
24
|
+
const listenTcp = async (address) => {
|
|
25
|
+
const listener$1 = new listener.TcpListener();
|
|
26
|
+
listener$1.listen(address);
|
|
27
|
+
return listener$1;
|
|
28
|
+
};
|
|
29
|
+
exports.connectTcp = connectTcp;
|
|
30
|
+
exports.connectTls = connectTls;
|
|
31
|
+
exports.listenTcp = listenTcp;
|
package/functions.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ConnectFunction, IListener, ListenFunction, TcpEndpoint, TlsConnectOptions } from '@fuman/net';
|
|
2
|
+
import { TcpConnection } from './connection.js';
|
|
3
|
+
export declare const connectTcp: ConnectFunction<TcpEndpoint, TcpConnection>;
|
|
4
|
+
export declare const connectTls: ConnectFunction<TlsConnectOptions, TcpConnection>;
|
|
5
|
+
export declare const listenTcp: ListenFunction<TcpEndpoint, IListener<TcpEndpoint>>;
|
package/functions.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { TcpConnection } from "./connection.js";
|
|
2
|
+
import { TcpListener } from "./listener.js";
|
|
3
|
+
const connectTcp = async (endpoint) => {
|
|
4
|
+
const connection = new TcpConnection();
|
|
5
|
+
await connection.connect(endpoint);
|
|
6
|
+
return connection;
|
|
7
|
+
};
|
|
8
|
+
const connectTls = async (opts) => {
|
|
9
|
+
if (opts.sni != null) {
|
|
10
|
+
throw new Error(".sni is not available in Bun");
|
|
11
|
+
}
|
|
12
|
+
if (opts.caCerts) {
|
|
13
|
+
throw new Error(".caCerts is not available in Bun");
|
|
14
|
+
}
|
|
15
|
+
if (opts.alpnProtocols) {
|
|
16
|
+
throw new Error(".alpnProtocols is not available in Bun");
|
|
17
|
+
}
|
|
18
|
+
const connection = new TcpConnection();
|
|
19
|
+
await connection.connect(opts, true);
|
|
20
|
+
return connection;
|
|
21
|
+
};
|
|
22
|
+
const listenTcp = async (address) => {
|
|
23
|
+
const listener = new TcpListener();
|
|
24
|
+
listener.listen(address);
|
|
25
|
+
return listener;
|
|
26
|
+
};
|
|
27
|
+
export {
|
|
28
|
+
connectTcp,
|
|
29
|
+
connectTls,
|
|
30
|
+
listenTcp
|
|
31
|
+
};
|
package/index.cjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const connection = require("./connection.cjs");
|
|
4
|
+
const functions = require("./functions.cjs");
|
|
5
|
+
const listener = require("./listener.cjs");
|
|
6
|
+
exports.TcpConnection = connection.TcpConnection;
|
|
7
|
+
exports.connectTcp = functions.connectTcp;
|
|
8
|
+
exports.connectTls = functions.connectTls;
|
|
9
|
+
exports.listenTcp = functions.listenTcp;
|
|
10
|
+
exports.TcpListener = listener.TcpListener;
|
package/index.d.ts
ADDED
package/index.js
ADDED
package/listener.cjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const utils = require("@fuman/utils");
|
|
4
|
+
const connection = require("./connection.cjs");
|
|
5
|
+
class TcpListener {
|
|
6
|
+
constructor() {
|
|
7
|
+
}
|
|
8
|
+
#listener;
|
|
9
|
+
#waiter;
|
|
10
|
+
listen(endpoint) {
|
|
11
|
+
this.#listener = Bun.listen({
|
|
12
|
+
hostname: endpoint.address,
|
|
13
|
+
port: endpoint.port,
|
|
14
|
+
socket: {
|
|
15
|
+
open: (socket) => {
|
|
16
|
+
if (!this.#waiter) {
|
|
17
|
+
socket.end();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const conn = connection.TcpConnection.from(socket);
|
|
21
|
+
socket.data = conn;
|
|
22
|
+
this.#waiter.resolve(conn);
|
|
23
|
+
this.#waiter = void 0;
|
|
24
|
+
},
|
|
25
|
+
error: (socket, error) => {
|
|
26
|
+
if (this.#waiter) {
|
|
27
|
+
this.#waiter.reject(error);
|
|
28
|
+
this.#waiter = void 0;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
socket.data?._handleError(socket, error);
|
|
32
|
+
},
|
|
33
|
+
data: (socket, data) => {
|
|
34
|
+
socket.data._handleData(socket, data);
|
|
35
|
+
},
|
|
36
|
+
drain: (socket) => {
|
|
37
|
+
socket.data._handleDrain();
|
|
38
|
+
},
|
|
39
|
+
close: (socket) => {
|
|
40
|
+
socket.data._handleClose();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
close() {
|
|
46
|
+
this.#listener.stop();
|
|
47
|
+
}
|
|
48
|
+
get address() {
|
|
49
|
+
return {
|
|
50
|
+
address: this.#listener.hostname,
|
|
51
|
+
port: this.#listener.port
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
async accept() {
|
|
55
|
+
this.#waiter = new utils.Deferred();
|
|
56
|
+
const connection2 = await this.#waiter.promise;
|
|
57
|
+
this.#waiter = void 0;
|
|
58
|
+
return connection2;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.TcpListener = TcpListener;
|
package/listener.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IListener, TcpEndpoint } from '@fuman/net';
|
|
2
|
+
import { TcpConnection } from './connection.js';
|
|
3
|
+
export declare class TcpListener implements IListener<TcpEndpoint, TcpConnection> {
|
|
4
|
+
#private;
|
|
5
|
+
constructor();
|
|
6
|
+
listen(endpoint: TcpEndpoint): void;
|
|
7
|
+
close(): void;
|
|
8
|
+
get address(): TcpEndpoint;
|
|
9
|
+
accept(): Promise<TcpConnection>;
|
|
10
|
+
}
|
package/listener.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Deferred } from "@fuman/utils";
|
|
2
|
+
import { TcpConnection } from "./connection.js";
|
|
3
|
+
class TcpListener {
|
|
4
|
+
constructor() {
|
|
5
|
+
}
|
|
6
|
+
#listener;
|
|
7
|
+
#waiter;
|
|
8
|
+
listen(endpoint) {
|
|
9
|
+
this.#listener = Bun.listen({
|
|
10
|
+
hostname: endpoint.address,
|
|
11
|
+
port: endpoint.port,
|
|
12
|
+
socket: {
|
|
13
|
+
open: (socket) => {
|
|
14
|
+
if (!this.#waiter) {
|
|
15
|
+
socket.end();
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const conn = TcpConnection.from(socket);
|
|
19
|
+
socket.data = conn;
|
|
20
|
+
this.#waiter.resolve(conn);
|
|
21
|
+
this.#waiter = void 0;
|
|
22
|
+
},
|
|
23
|
+
error: (socket, error) => {
|
|
24
|
+
if (this.#waiter) {
|
|
25
|
+
this.#waiter.reject(error);
|
|
26
|
+
this.#waiter = void 0;
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
socket.data?._handleError(socket, error);
|
|
30
|
+
},
|
|
31
|
+
data: (socket, data) => {
|
|
32
|
+
socket.data._handleData(socket, data);
|
|
33
|
+
},
|
|
34
|
+
drain: (socket) => {
|
|
35
|
+
socket.data._handleDrain();
|
|
36
|
+
},
|
|
37
|
+
close: (socket) => {
|
|
38
|
+
socket.data._handleClose();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
close() {
|
|
44
|
+
this.#listener.stop();
|
|
45
|
+
}
|
|
46
|
+
get address() {
|
|
47
|
+
return {
|
|
48
|
+
address: this.#listener.hostname,
|
|
49
|
+
port: this.#listener.port
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
async accept() {
|
|
53
|
+
this.#waiter = new Deferred();
|
|
54
|
+
const connection = await this.#waiter.promise;
|
|
55
|
+
this.#waiter = void 0;
|
|
56
|
+
return connection;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export {
|
|
60
|
+
TcpListener
|
|
61
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fuman/bun",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"description": "bun-specific utilities",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"scripts": {},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@fuman/io": "^0.0.1",
|
|
10
|
+
"@fuman/net": "^0.0.1",
|
|
11
|
+
"@fuman/utils": "^0.0.1"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"import": {
|
|
16
|
+
"types": "./index.d.ts",
|
|
17
|
+
"default": "./index.js"
|
|
18
|
+
},
|
|
19
|
+
"require": {
|
|
20
|
+
"types": "./index.d.cts",
|
|
21
|
+
"default": "./index.cjs"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"author": "",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/teidesu/fuman.git"
|
|
30
|
+
}
|
|
31
|
+
}
|