@react-native-ohos/react-native-tcp-socket 6.3.1-rc.3 → 6.3.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.
Files changed (60) hide show
  1. package/LICENSE +21 -21
  2. package/README.OpenSource +10 -10
  3. package/README.md +12 -12
  4. package/harmony/tcp_socket/BuildProfile.ets +16 -16
  5. package/harmony/tcp_socket/Index.ets +5 -5
  6. package/harmony/tcp_socket/build-profile.json5 +31 -31
  7. package/harmony/tcp_socket/hvigorfile.ts +6 -6
  8. package/harmony/tcp_socket/obfuscation-rules.txt +22 -22
  9. package/harmony/tcp_socket/oh-package.json5 +11 -11
  10. package/harmony/tcp_socket/src/main/cpp/CMakeLists.txt +8 -8
  11. package/harmony/tcp_socket/src/main/cpp/TcpSocketPackage.h +18 -18
  12. package/harmony/tcp_socket/src/main/cpp/generated/RNOH/generated/BaseReactNativeTcpSocketPackage.h +72 -72
  13. package/harmony/tcp_socket/src/main/cpp/generated/RNOH/generated/turbo_modules/TcpSocketModule.cpp +28 -28
  14. package/harmony/tcp_socket/src/main/cpp/generated/RNOH/generated/turbo_modules/TcpSocketModule.h +16 -16
  15. package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/ComponentDescriptors.h +24 -24
  16. package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/EventEmitters.cpp +16 -16
  17. package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/EventEmitters.h +17 -17
  18. package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/Props.cpp +19 -19
  19. package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/Props.h +18 -18
  20. package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/ShadowNodes.cpp +17 -17
  21. package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/ShadowNodes.h +23 -23
  22. package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/States.cpp +16 -16
  23. package/harmony/tcp_socket/src/main/cpp/generated/react/renderer/components/react_native_tcp_socket/States.h +18 -18
  24. package/harmony/tcp_socket/src/main/ets/Logger.ts +45 -45
  25. package/harmony/tcp_socket/src/main/ets/TcpEventListener.ts +120 -120
  26. package/harmony/tcp_socket/src/main/ets/TcpSocket.ts +16 -16
  27. package/harmony/tcp_socket/src/main/ets/TcpSocketClient.ts +443 -443
  28. package/harmony/tcp_socket/src/main/ets/TcpSocketPackage.ts +27 -27
  29. package/harmony/tcp_socket/src/main/ets/TcpSocketServer.ts +150 -150
  30. package/harmony/tcp_socket/src/main/ets/TcpSocketTurboModule.ts +224 -224
  31. package/harmony/tcp_socket/src/main/ets/generated/components/ts.ts +5 -5
  32. package/harmony/tcp_socket/src/main/ets/generated/index.ets +5 -5
  33. package/harmony/tcp_socket/src/main/ets/generated/ts.ts +6 -6
  34. package/harmony/tcp_socket/src/main/ets/generated/turboModules/TcpSocketModule.ts +38 -38
  35. package/harmony/tcp_socket/src/main/ets/generated/turboModules/ts.ts +5 -5
  36. package/harmony/tcp_socket/src/main/module.json5 +11 -11
  37. package/harmony/tcp_socket/src/main/resources/base/element/string.json +8 -8
  38. package/harmony/tcp_socket/src/main/resources/en_US/element/string.json +8 -8
  39. package/harmony/tcp_socket/src/main/resources/zh_CN/element/string.json +8 -8
  40. package/harmony/tcp_socket/src/ohosTest/ets/test/Ability.test.ets +34 -34
  41. package/harmony/tcp_socket/src/ohosTest/ets/test/List.test.ets +4 -4
  42. package/harmony/tcp_socket/src/ohosTest/module.json5 +13 -13
  43. package/harmony/tcp_socket/src/test/List.test.ets +4 -4
  44. package/harmony/tcp_socket/src/test/LocalUnit.test.ets +32 -32
  45. package/harmony/tcp_socket/ts.ts +6 -6
  46. package/harmony/tcp_socket.har +0 -0
  47. package/lib/types/Globals.d.ts +2 -2
  48. package/lib/types/Server.d.ts +137 -137
  49. package/lib/types/Socket.d.ts +272 -272
  50. package/lib/types/TLSServer.d.ts +28 -28
  51. package/lib/types/TLSSocket.d.ts +50 -50
  52. package/lib/types/index.d.ts +80 -80
  53. package/package.json +76 -76
  54. package/src/Globals.js +12 -12
  55. package/src/Server.js +271 -271
  56. package/src/Socket.js +513 -513
  57. package/src/TLSServer.js +70 -70
  58. package/src/TLSSocket.js +93 -93
  59. package/src/TcpSocketModule.ts +39 -39
  60. package/src/index.js +144 -144
package/src/Server.js CHANGED
@@ -1,272 +1,272 @@
1
- 'use strict';
2
-
3
- import { TurboModuleRegistry, NativeModules } from 'react-native';
4
- import EventEmitter from 'eventemitter3';
5
- import Socket from './Socket';
6
- import { nativeEventEmitter, getNextId } from './Globals';
7
-
8
- const Sockets = TurboModuleRegistry ? TurboModuleRegistry.get('TcpSocketModule') : NativeModules.TcpSockets;
9
-
10
- /**
11
- * @typedef {object} ServerOptions
12
- * @property {boolean} [noDelay]
13
- * @property {boolean} [keepAlive]
14
- * @property {number} [keepAliveInitialDelay]
15
- * @property {boolean} [allowHalfOpen]
16
- * @property {boolean} [pauseOnConnect]
17
- *
18
- * @typedef {import('./TLSSocket').default} TLSSocket
19
- *
20
- * @typedef {object} ServerEvents
21
- * @property {() => void} close
22
- * @property {(socket: Socket) => void} connection
23
- * @property {() => void} listening
24
- * @property {(err: Error) => void} error
25
- * @property {(tlsSocket: TLSSocket) => void} secureConnection
26
- *
27
- * @extends {EventEmitter<ServerEvents, any>}
28
- */
29
- export default class Server extends EventEmitter {
30
- /**
31
- * @param {ServerOptions | ((socket: Socket) => void)} [options] Server options or connection listener
32
- * @param {(socket: Socket) => void} [connectionCallback] Automatically set as a listener for the `'connection'` event.
33
- */
34
- constructor(options, connectionCallback) {
35
- super();
36
- /** @protected @readonly */
37
- this._id = getNextId();
38
- /** @protected @readonly */
39
- this._eventEmitter = nativeEventEmitter;
40
- /** @private @type {Set<Socket>} */
41
- this._connections = new Set();
42
- /** @private */
43
- this._localAddress = undefined;
44
- /** @private */
45
- this._localPort = undefined;
46
- /** @private */
47
- this._localFamily = undefined;
48
- /** @private @type {ServerOptions} */
49
- this._serverOptions = {};
50
- this.listening = false;
51
-
52
- // Handle optional options argument
53
- if (typeof options === 'function') {
54
- /** @type {(socket: Socket) => void} */
55
- const callback = options;
56
- this.on('connection', callback);
57
- options = {};
58
- } else if (options && typeof options === 'object') {
59
- this._serverOptions = { ...options };
60
- if (typeof connectionCallback === 'function') {
61
- this.on('connection', connectionCallback);
62
- }
63
- }
64
-
65
- this._registerEvents();
66
- this.on('close', this._setDisconnected, this);
67
- }
68
-
69
- /**
70
- * Start a server listening for connections.
71
- *
72
- * This function is asynchronous. When the server starts listening, the `'listening'` event will be emitted.
73
- * The last parameter `callback` will be added as a listener for the `'listening'` event.
74
- *
75
- * The `server.listen()` method can be called again if and only if there was an error during the first
76
- * `server.listen()` call or `server.close()` has been called. Otherwise, an `ERR_SERVER_ALREADY_LISTEN`
77
- * error will be thrown.
78
- *
79
- * @param {{ port: number; host?: string; reuseAddress?: boolean} | number} options Options or port
80
- * @param {string | (() => void)} [callback_or_host] Callback or host string
81
- * @param {() => void} [callback] Callback function
82
- * @returns {Server}
83
- */
84
- listen(options, callback_or_host, callback) {
85
- if (this._localAddress !== undefined) throw new Error('ERR_SERVER_ALREADY_LISTEN');
86
-
87
- /** @type {{ port: number; host: string; reuseAddress?: boolean }} */
88
- let listenOptions = { port: 0, host: '0.0.0.0' };
89
- /** @type {(() => void) | undefined} */
90
- let cb;
91
-
92
- // Handle different argument patterns
93
- if (typeof options === 'number') {
94
- // listen(port, [host], [callback])
95
- listenOptions.port = options;
96
- if (typeof callback_or_host === 'string') {
97
- listenOptions.host = callback_or_host;
98
- cb = callback;
99
- } else if (typeof callback_or_host === 'function') {
100
- cb = callback_or_host;
101
- }
102
- } else if (typeof options === 'object') {
103
- // listen(options, [callback])
104
- listenOptions = {
105
- port: options.port,
106
- host: options.host || '0.0.0.0',
107
- reuseAddress: options.reuseAddress,
108
- tls: options.tls
109
- };
110
- if (typeof callback_or_host === 'function') {
111
- cb = callback_or_host;
112
- }
113
- } else {
114
- throw new TypeError('options must be an object or a number');
115
- }
116
-
117
- // Add callback as a listener for the listening event
118
- if (typeof cb === 'function') {
119
- this.once('listening', cb);
120
- }
121
-
122
- this.once('listening', () => {
123
- this.listening = true;
124
- });
125
-
126
- Sockets.listen(this._id, listenOptions);
127
- return this;
128
- }
129
-
130
- /**
131
- * Asynchronously get the number of concurrent connections on the server.
132
- *
133
- * Callback should take two arguments `err` and `count`.
134
- *
135
- * @param {(err: Error | null, count: number) => void} callback
136
- * @returns {Server}
137
- */
138
- getConnections(callback) {
139
- callback(null, this._connections.size);
140
- return this;
141
- }
142
-
143
- /**
144
- * Stops the server from accepting new connections and keeps existing connections.
145
- * This function is asynchronous, the server is finally closed when all connections are ended and the server emits a `'close'` event.
146
- * The optional callback will be called once the `'close'` event occurs. Unlike that event, it will be called with an `Error` as its
147
- * only argument if the server was not open when it was closed.
148
- *
149
- * @param {(err?: Error) => void} [callback] Called when the server is closed.
150
- * @returns {Server}
151
- */
152
- close(callback) {
153
- if (!this._localAddress) {
154
- callback?.(new Error('ERR_SERVER_NOT_RUNNING'));
155
- return this;
156
- }
157
- if (callback) this.once('close', callback);
158
- this.listening = false;
159
- Sockets.close(this._id);
160
- if (this._connections.size === 0) this.emit('close');
161
- return this;
162
- }
163
-
164
- /**
165
- * Returns the bound `address`, the address `family` name, and `port` of the server as reported by the operating system if listening
166
- * on an IP socket (useful to find which port was assigned when getting an OS-assigned address):
167
- * `{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`.
168
- *
169
- * @returns {import('./Socket').AddressInfo | null}
170
- */
171
- address() {
172
- if (!this._localAddress) return null;
173
- return { address: this._localAddress, port: this._localPort, family: this._localFamily };
174
- }
175
-
176
- ref() {
177
- console.warn('react-native-tcp-socket: Server.ref() method will have no effect.');
178
- return this;
179
- }
180
-
181
- unref() {
182
- console.warn('react-native-tcp-socket: Server.unref() method will have no effect.');
183
- return this;
184
- }
185
-
186
- /**
187
- * @private
188
- */
189
- _registerEvents() {
190
- this._listeningListener = this._eventEmitter.addListener('listening', (evt) => {
191
- if (evt.id !== this._id) return;
192
- this._localAddress = evt.connection.localAddress;
193
- this._localPort = evt.connection.localPort;
194
- this._localFamily = evt.connection.localFamily;
195
- this.emit('listening');
196
- });
197
- this._errorListener = this._eventEmitter.addListener('error', (evt) => {
198
- if (evt.id !== this._id) return;
199
- this.close();
200
- this.emit('error', evt.error);
201
- });
202
- this._connectionsListener = this._eventEmitter.addListener('connection', (evt) => {
203
- if (evt.id !== this._id) return;
204
- const newSocket = this._buildSocket(evt.info);
205
- this._addConnection(newSocket);
206
- this.emit('connection', newSocket);
207
- });
208
- }
209
-
210
- /**
211
- * @private
212
- */
213
- _setDisconnected() {
214
- this._localAddress = undefined;
215
- this._localPort = undefined;
216
- this._localFamily = undefined;
217
- }
218
-
219
- /**
220
- * @protected
221
- * @param {Socket} socket
222
- */
223
- _addConnection(socket) {
224
- // Emit 'close' when all connection closed
225
- socket.on('close', () => {
226
- this._connections.delete(socket);
227
- if (!this.listening && this._connections.size === 0) this.emit('close');
228
- });
229
- this._connections.add(socket);
230
- }
231
-
232
- /**
233
- * @protected
234
- * @param {{ id: number; connection: import('./Socket').NativeConnectionInfo; }} info
235
- * @returns {Socket}
236
- */
237
- _buildSocket(info) {
238
- const newSocket = new Socket();
239
- newSocket._setId(info.id);
240
- newSocket._setConnected(info.connection);
241
-
242
- // Apply server options to the socket if they exist
243
- if (this._serverOptions) {
244
- if (this._serverOptions.noDelay !== undefined) {
245
- newSocket.setNoDelay(this._serverOptions.noDelay);
246
- }
247
-
248
- if (this._serverOptions.keepAlive !== undefined) {
249
- const keepAliveDelay = this._serverOptions.keepAliveInitialDelay || 0;
250
- newSocket.setKeepAlive(this._serverOptions.keepAlive, keepAliveDelay);
251
- }
252
- }
253
-
254
- return newSocket;
255
- }
256
-
257
- /**
258
- * Apply server socket options to a newly connected socket
259
- * @param {Socket} socket
260
- * @private
261
- */
262
- _applySocketOptions(socket) {
263
- if (this._serverOptions.noDelay !== undefined) {
264
- socket.setNoDelay(this._serverOptions.noDelay);
265
- }
266
-
267
- if (this._serverOptions.keepAlive !== undefined) {
268
- const keepAliveDelay = this._serverOptions.keepAliveInitialDelay || 0;
269
- socket.setKeepAlive(this._serverOptions.keepAlive, keepAliveDelay);
270
- }
271
- }
1
+ 'use strict';
2
+
3
+ import { TurboModuleRegistry, NativeModules } from 'react-native';
4
+ import EventEmitter from 'eventemitter3';
5
+ import Socket from './Socket';
6
+ import { nativeEventEmitter, getNextId } from './Globals';
7
+
8
+ const Sockets = TurboModuleRegistry ? TurboModuleRegistry.get('TcpSocketModule') : NativeModules.TcpSockets;
9
+
10
+ /**
11
+ * @typedef {object} ServerOptions
12
+ * @property {boolean} [noDelay]
13
+ * @property {boolean} [keepAlive]
14
+ * @property {number} [keepAliveInitialDelay]
15
+ * @property {boolean} [allowHalfOpen]
16
+ * @property {boolean} [pauseOnConnect]
17
+ *
18
+ * @typedef {import('./TLSSocket').default} TLSSocket
19
+ *
20
+ * @typedef {object} ServerEvents
21
+ * @property {() => void} close
22
+ * @property {(socket: Socket) => void} connection
23
+ * @property {() => void} listening
24
+ * @property {(err: Error) => void} error
25
+ * @property {(tlsSocket: TLSSocket) => void} secureConnection
26
+ *
27
+ * @extends {EventEmitter<ServerEvents, any>}
28
+ */
29
+ export default class Server extends EventEmitter {
30
+ /**
31
+ * @param {ServerOptions | ((socket: Socket) => void)} [options] Server options or connection listener
32
+ * @param {(socket: Socket) => void} [connectionCallback] Automatically set as a listener for the `'connection'` event.
33
+ */
34
+ constructor(options, connectionCallback) {
35
+ super();
36
+ /** @protected @readonly */
37
+ this._id = getNextId();
38
+ /** @protected @readonly */
39
+ this._eventEmitter = nativeEventEmitter;
40
+ /** @private @type {Set<Socket>} */
41
+ this._connections = new Set();
42
+ /** @private */
43
+ this._localAddress = undefined;
44
+ /** @private */
45
+ this._localPort = undefined;
46
+ /** @private */
47
+ this._localFamily = undefined;
48
+ /** @private @type {ServerOptions} */
49
+ this._serverOptions = {};
50
+ this.listening = false;
51
+
52
+ // Handle optional options argument
53
+ if (typeof options === 'function') {
54
+ /** @type {(socket: Socket) => void} */
55
+ const callback = options;
56
+ this.on('connection', callback);
57
+ options = {};
58
+ } else if (options && typeof options === 'object') {
59
+ this._serverOptions = { ...options };
60
+ if (typeof connectionCallback === 'function') {
61
+ this.on('connection', connectionCallback);
62
+ }
63
+ }
64
+
65
+ this._registerEvents();
66
+ this.on('close', this._setDisconnected, this);
67
+ }
68
+
69
+ /**
70
+ * Start a server listening for connections.
71
+ *
72
+ * This function is asynchronous. When the server starts listening, the `'listening'` event will be emitted.
73
+ * The last parameter `callback` will be added as a listener for the `'listening'` event.
74
+ *
75
+ * The `server.listen()` method can be called again if and only if there was an error during the first
76
+ * `server.listen()` call or `server.close()` has been called. Otherwise, an `ERR_SERVER_ALREADY_LISTEN`
77
+ * error will be thrown.
78
+ *
79
+ * @param {{ port: number; host?: string; reuseAddress?: boolean} | number} options Options or port
80
+ * @param {string | (() => void)} [callback_or_host] Callback or host string
81
+ * @param {() => void} [callback] Callback function
82
+ * @returns {Server}
83
+ */
84
+ listen(options, callback_or_host, callback) {
85
+ if (this._localAddress !== undefined) throw new Error('ERR_SERVER_ALREADY_LISTEN');
86
+
87
+ /** @type {{ port: number; host: string; reuseAddress?: boolean }} */
88
+ let listenOptions = { port: 0, host: '0.0.0.0' };
89
+ /** @type {(() => void) | undefined} */
90
+ let cb;
91
+
92
+ // Handle different argument patterns
93
+ if (typeof options === 'number') {
94
+ // listen(port, [host], [callback])
95
+ listenOptions.port = options;
96
+ if (typeof callback_or_host === 'string') {
97
+ listenOptions.host = callback_or_host;
98
+ cb = callback;
99
+ } else if (typeof callback_or_host === 'function') {
100
+ cb = callback_or_host;
101
+ }
102
+ } else if (typeof options === 'object') {
103
+ // listen(options, [callback])
104
+ listenOptions = {
105
+ port: options.port,
106
+ host: options.host || '0.0.0.0',
107
+ reuseAddress: options.reuseAddress,
108
+ tls: options.tls
109
+ };
110
+ if (typeof callback_or_host === 'function') {
111
+ cb = callback_or_host;
112
+ }
113
+ } else {
114
+ throw new TypeError('options must be an object or a number');
115
+ }
116
+
117
+ // Add callback as a listener for the listening event
118
+ if (typeof cb === 'function') {
119
+ this.once('listening', cb);
120
+ }
121
+
122
+ this.once('listening', () => {
123
+ this.listening = true;
124
+ });
125
+
126
+ Sockets.listen(this._id, listenOptions);
127
+ return this;
128
+ }
129
+
130
+ /**
131
+ * Asynchronously get the number of concurrent connections on the server.
132
+ *
133
+ * Callback should take two arguments `err` and `count`.
134
+ *
135
+ * @param {(err: Error | null, count: number) => void} callback
136
+ * @returns {Server}
137
+ */
138
+ getConnections(callback) {
139
+ callback(null, this._connections.size);
140
+ return this;
141
+ }
142
+
143
+ /**
144
+ * Stops the server from accepting new connections and keeps existing connections.
145
+ * This function is asynchronous, the server is finally closed when all connections are ended and the server emits a `'close'` event.
146
+ * The optional callback will be called once the `'close'` event occurs. Unlike that event, it will be called with an `Error` as its
147
+ * only argument if the server was not open when it was closed.
148
+ *
149
+ * @param {(err?: Error) => void} [callback] Called when the server is closed.
150
+ * @returns {Server}
151
+ */
152
+ close(callback) {
153
+ if (!this._localAddress) {
154
+ callback?.(new Error('ERR_SERVER_NOT_RUNNING'));
155
+ return this;
156
+ }
157
+ if (callback) this.once('close', callback);
158
+ this.listening = false;
159
+ Sockets.close(this._id);
160
+ if (this._connections.size === 0) this.emit('close');
161
+ return this;
162
+ }
163
+
164
+ /**
165
+ * Returns the bound `address`, the address `family` name, and `port` of the server as reported by the operating system if listening
166
+ * on an IP socket (useful to find which port was assigned when getting an OS-assigned address):
167
+ * `{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`.
168
+ *
169
+ * @returns {import('./Socket').AddressInfo | null}
170
+ */
171
+ address() {
172
+ if (!this._localAddress) return null;
173
+ return { address: this._localAddress, port: this._localPort, family: this._localFamily };
174
+ }
175
+
176
+ ref() {
177
+ console.warn('react-native-tcp-socket: Server.ref() method will have no effect.');
178
+ return this;
179
+ }
180
+
181
+ unref() {
182
+ console.warn('react-native-tcp-socket: Server.unref() method will have no effect.');
183
+ return this;
184
+ }
185
+
186
+ /**
187
+ * @private
188
+ */
189
+ _registerEvents() {
190
+ this._listeningListener = this._eventEmitter.addListener('listening', (evt) => {
191
+ if (evt.id !== this._id) return;
192
+ this._localAddress = evt.connection.localAddress;
193
+ this._localPort = evt.connection.localPort;
194
+ this._localFamily = evt.connection.localFamily;
195
+ this.emit('listening');
196
+ });
197
+ this._errorListener = this._eventEmitter.addListener('error', (evt) => {
198
+ if (evt.id !== this._id) return;
199
+ this.close();
200
+ this.emit('error', evt.error);
201
+ });
202
+ this._connectionsListener = this._eventEmitter.addListener('connection', (evt) => {
203
+ if (evt.id !== this._id) return;
204
+ const newSocket = this._buildSocket(evt.info);
205
+ this._addConnection(newSocket);
206
+ this.emit('connection', newSocket);
207
+ });
208
+ }
209
+
210
+ /**
211
+ * @private
212
+ */
213
+ _setDisconnected() {
214
+ this._localAddress = undefined;
215
+ this._localPort = undefined;
216
+ this._localFamily = undefined;
217
+ }
218
+
219
+ /**
220
+ * @protected
221
+ * @param {Socket} socket
222
+ */
223
+ _addConnection(socket) {
224
+ // Emit 'close' when all connection closed
225
+ socket.on('close', () => {
226
+ this._connections.delete(socket);
227
+ if (!this.listening && this._connections.size === 0) this.emit('close');
228
+ });
229
+ this._connections.add(socket);
230
+ }
231
+
232
+ /**
233
+ * @protected
234
+ * @param {{ id: number; connection: import('./Socket').NativeConnectionInfo; }} info
235
+ * @returns {Socket}
236
+ */
237
+ _buildSocket(info) {
238
+ const newSocket = new Socket();
239
+ newSocket._setId(info.id);
240
+ newSocket._setConnected(info.connection);
241
+
242
+ // Apply server options to the socket if they exist
243
+ if (this._serverOptions) {
244
+ if (this._serverOptions.noDelay !== undefined) {
245
+ newSocket.setNoDelay(this._serverOptions.noDelay);
246
+ }
247
+
248
+ if (this._serverOptions.keepAlive !== undefined) {
249
+ const keepAliveDelay = this._serverOptions.keepAliveInitialDelay || 0;
250
+ newSocket.setKeepAlive(this._serverOptions.keepAlive, keepAliveDelay);
251
+ }
252
+ }
253
+
254
+ return newSocket;
255
+ }
256
+
257
+ /**
258
+ * Apply server socket options to a newly connected socket
259
+ * @param {Socket} socket
260
+ * @private
261
+ */
262
+ _applySocketOptions(socket) {
263
+ if (this._serverOptions.noDelay !== undefined) {
264
+ socket.setNoDelay(this._serverOptions.noDelay);
265
+ }
266
+
267
+ if (this._serverOptions.keepAlive !== undefined) {
268
+ const keepAliveDelay = this._serverOptions.keepAliveInitialDelay || 0;
269
+ socket.setKeepAlive(this._serverOptions.keepAlive, keepAliveDelay);
270
+ }
271
+ }
272
272
  }