-
Notifications
You must be signed in to change notification settings - Fork 17
/
socket.ts
112 lines (93 loc) · 2.34 KB
/
socket.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import type * as net from "node:net";
import { Callback, BufferEncoding } from "../../_internal/types";
import { Duplex } from "../stream/duplex";
// Docs: https://nodejs.org/api/net.html#net_class_net_socket
export class Socket extends Duplex implements net.Socket {
readonly __unenv__ = true;
readonly bufferSize: number = 0;
readonly bytesRead: number = 0;
readonly bytesWritten: number = 0;
readonly connecting: boolean = false;
readonly destroyed: boolean = false;
readonly pending: boolean = false;
readonly localAddress: string = "";
readonly localPort: number = 0;
readonly remoteAddress?: string = "";
readonly remoteFamily?: string = "";
readonly remotePort?: number = 0;
readonly autoSelectFamilyAttemptedAddresses = [];
readonly readyState: net.SocketReadyState = "readOnly";
constructor(_options?: net.SocketConstructorOpts) {
super();
}
write(
_buffer: Uint8Array | string,
_arg1?: BufferEncoding | Callback<Error | undefined>,
_arg2?: Callback<Error | undefined>,
): boolean {
return false;
}
connect(
_arg1: number | string | net.SocketConnectOpts,
_arg2?: string | Callback,
_arg3?: Callback,
) {
return this;
}
end(
_arg1?: Callback | Uint8Array | string,
_arg2?: BufferEncoding | Callback,
_arg3?: Callback,
) {
return this;
}
setEncoding(_encoding?: BufferEncoding): this {
return this;
}
pause() {
return this;
}
resume() {
return this;
}
setTimeout(_timeout: number, _callback?: Callback): this {
return this;
}
setNoDelay(_noDelay?: boolean): this {
return this;
}
setKeepAlive(_enable?: boolean, _initialDelay?: number): this {
return this;
}
address() {
return {};
}
unref() {
return this;
}
ref() {
return this;
}
destroySoon() {
this.destroy();
}
resetAndDestroy() {
const err = new Error("ERR_SOCKET_CLOSED");
(err as any).code = "ERR_SOCKET_CLOSED";
this.destroy(err);
return this;
}
}
export class SocketAddress implements net.SocketAddress {
readonly __unenv__ = true;
address: string;
family: "ipv4" | "ipv6";
port: number;
flowlabel: number;
constructor(options: net.SocketAddress) {
this.address = options.address;
this.family = options.family;
this.port = options.port;
this.flowlabel = options.flowlabel;
}
}