react-native-nitro-net 0.5.0 → 0.5.2
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/android/libs/arm64-v8a/librust_c_net.so +0 -0
- package/android/libs/armeabi-v7a/librust_c_net.so +0 -0
- package/android/libs/x86/librust_c_net.so +0 -0
- package/android/libs/x86_64/librust_c_net.so +0 -0
- package/ios/Frameworks/RustCNet.xcframework/ios-arm64/RustCNet.framework/RustCNet +0 -0
- package/ios/Frameworks/RustCNet.xcframework/ios-arm64_x86_64-simulator/RustCNet.framework/RustCNet +0 -0
- package/lib/http.d.ts +3 -0
- package/lib/http.d.ts.map +1 -1
- package/lib/http.js +95 -45
- package/lib/net.d.ts +2 -3
- package/lib/net.d.ts.map +1 -1
- package/lib/net.js +57 -15
- package/package.json +3 -3
- package/src/http.ts +100 -43
- package/src/net.ts +58 -18
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/ios/Frameworks/RustCNet.xcframework/ios-arm64_x86_64-simulator/RustCNet.framework/RustCNet
CHANGED
|
Binary file
|
package/lib/http.d.ts
CHANGED
|
@@ -180,6 +180,8 @@ export declare class ClientRequest extends OutgoingMessage {
|
|
|
180
180
|
private _ended;
|
|
181
181
|
private _expectContinue;
|
|
182
182
|
private _continueReceived;
|
|
183
|
+
private _getChunkByteLength;
|
|
184
|
+
private _getPendingBodyLength;
|
|
183
185
|
constructor(options: RequestOptions, callback?: (res: IncomingMessage) => void);
|
|
184
186
|
/** @internal */
|
|
185
187
|
onSocket(socket: Socket | null): void;
|
|
@@ -188,6 +190,7 @@ export declare class ClientRequest extends OutgoingMessage {
|
|
|
188
190
|
private _socketCleanup?;
|
|
189
191
|
private _cleanupSocket;
|
|
190
192
|
private _finishResponse;
|
|
193
|
+
private _isFlushing;
|
|
191
194
|
private _flushPendingWrites;
|
|
192
195
|
private _finishRequest;
|
|
193
196
|
private _sendRequest;
|
package/lib/http.d.ts.map
CHAN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EAAE,cAAc,KAAK,IAAI,GAAG,MAAM,CAAC;AAC5G,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,EAAE,eAAe,CAAC,EAAE,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,KAAK,IAAI,GAAG,MAAM,CAAC;AAQpI,wBAAgB,OAAO,CACnB,YAAY,EAAE,MAAM,GAAG,GAAG,GAAG,cAAc,EAC3C,iBAAiB,CAAC,EAAE,cAAc,GAAG,CAAC,CAAC,GAAG,EAAE,eAAe,KAAK,IAAI,CAAC,EACrE,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,IAAI,GAC1C,aAAa,CAgCf;AAED,wBAAgB,GAAG,CACf,YAAY,EAAE,MAAM,GAAG,GAAG,GAAG,cAAc,EAC3C,iBAAiB,CAAC,EAAE,cAAc,GAAG,CAAC,CAAC,GAAG,EAAE,eAAe,KAAK,IAAI,CAAC,EACrE,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,IAAI,GAC1C,aAAa,CAIf"}
|
package/lib/http.js
CHANGED
|
@@ -260,8 +260,16 @@ export class OutgoingMessage extends Writable {
|
|
|
260
260
|
this._trailers = headers;
|
|
261
261
|
}
|
|
262
262
|
end(chunk, encoding, callback) {
|
|
263
|
-
|
|
264
|
-
|
|
263
|
+
if (typeof chunk === 'function') {
|
|
264
|
+
callback = chunk;
|
|
265
|
+
chunk = null;
|
|
266
|
+
encoding = null;
|
|
267
|
+
}
|
|
268
|
+
else if (typeof encoding === 'function') {
|
|
269
|
+
callback = encoding;
|
|
270
|
+
encoding = null;
|
|
271
|
+
}
|
|
272
|
+
if (chunk != null) {
|
|
265
273
|
this.write(chunk, encoding);
|
|
266
274
|
}
|
|
267
275
|
super.end(callback);
|
|
@@ -324,27 +332,31 @@ export class ServerResponse extends OutgoingMessage {
|
|
|
324
332
|
return super.write(chunk, encoding, callback);
|
|
325
333
|
}
|
|
326
334
|
end(chunk, encoding, callback) {
|
|
335
|
+
if (typeof chunk === 'function') {
|
|
336
|
+
callback = chunk;
|
|
337
|
+
chunk = null;
|
|
338
|
+
encoding = null;
|
|
339
|
+
}
|
|
340
|
+
else if (typeof encoding === 'function') {
|
|
341
|
+
callback = encoding;
|
|
342
|
+
encoding = null;
|
|
343
|
+
}
|
|
327
344
|
if (!this.headersSent) {
|
|
328
345
|
// If we have a single chunk and no headers sent yet, we can add Content-Length
|
|
329
346
|
// to avoid chunked encoding for simple responses.
|
|
330
|
-
if (chunk) {
|
|
331
|
-
const len = typeof chunk === 'string' ? Buffer.byteLength(chunk, encoding) : chunk.length;
|
|
347
|
+
if (chunk != null) {
|
|
348
|
+
const len = typeof chunk === 'string' ? Buffer.byteLength(chunk, encoding || undefined) : chunk.length;
|
|
332
349
|
this.setHeader('Content-Length', len);
|
|
333
350
|
}
|
|
334
|
-
else {
|
|
351
|
+
else if (!this.hasHeader('Transfer-Encoding')) {
|
|
335
352
|
this.setHeader('Content-Length', 0);
|
|
336
353
|
}
|
|
337
354
|
this._sendResponseHeaders();
|
|
338
355
|
}
|
|
339
|
-
if (
|
|
340
|
-
|
|
341
|
-
}
|
|
342
|
-
else if (chunk == null) {
|
|
343
|
-
super.end(callback);
|
|
344
|
-
}
|
|
345
|
-
else {
|
|
346
|
-
super.end(chunk, encoding, callback);
|
|
356
|
+
if (chunk != null) {
|
|
357
|
+
this.write(chunk, encoding);
|
|
347
358
|
}
|
|
359
|
+
super.end(callback);
|
|
348
360
|
return this;
|
|
349
361
|
}
|
|
350
362
|
}
|
|
@@ -816,6 +828,24 @@ export class Agent extends EventEmitter {
|
|
|
816
828
|
}
|
|
817
829
|
export const globalAgent = new Agent();
|
|
818
830
|
export class ClientRequest extends OutgoingMessage {
|
|
831
|
+
_getChunkByteLength(chunk, encoding) {
|
|
832
|
+
if (chunk == null)
|
|
833
|
+
return 0;
|
|
834
|
+
const normalizedEncoding = typeof encoding === 'string' ? encoding : undefined;
|
|
835
|
+
if (typeof chunk === 'string') {
|
|
836
|
+
return Buffer.byteLength(chunk, normalizedEncoding);
|
|
837
|
+
}
|
|
838
|
+
if (typeof chunk.length === 'number') {
|
|
839
|
+
return chunk.length;
|
|
840
|
+
}
|
|
841
|
+
const buffer = Buffer.from(chunk, normalizedEncoding);
|
|
842
|
+
return buffer.length;
|
|
843
|
+
}
|
|
844
|
+
_getPendingBodyLength() {
|
|
845
|
+
return this._pendingWrites.reduce((total, pending) => {
|
|
846
|
+
return total + this._getChunkByteLength(pending.chunk, pending.encoding);
|
|
847
|
+
}, 0);
|
|
848
|
+
}
|
|
819
849
|
constructor(options, callback) {
|
|
820
850
|
super();
|
|
821
851
|
this._connected = false;
|
|
@@ -823,6 +853,7 @@ export class ClientRequest extends OutgoingMessage {
|
|
|
823
853
|
this._ended = false;
|
|
824
854
|
this._expectContinue = false;
|
|
825
855
|
this._continueReceived = false;
|
|
856
|
+
this._isFlushing = false;
|
|
826
857
|
this._options = options;
|
|
827
858
|
this.method = options.method || 'GET';
|
|
828
859
|
this.path = options.path || '/';
|
|
@@ -1015,27 +1046,39 @@ export class ClientRequest extends OutgoingMessage {
|
|
|
1015
1046
|
this.emit('close');
|
|
1016
1047
|
}
|
|
1017
1048
|
_flushPendingWrites() {
|
|
1018
|
-
if (!this.socket)
|
|
1019
|
-
return;
|
|
1020
|
-
if (!this.headersSent)
|
|
1021
|
-
this._sendRequest();
|
|
1022
|
-
// If we are waiting for 100-continue, don't flush yet
|
|
1023
|
-
if (this._expectContinue && !this._continueReceived) {
|
|
1049
|
+
if (!this.socket || this._isFlushing)
|
|
1024
1050
|
return;
|
|
1051
|
+
this._isFlushing = true;
|
|
1052
|
+
try {
|
|
1053
|
+
if (!this.headersSent)
|
|
1054
|
+
this._sendRequest();
|
|
1055
|
+
// If we are waiting for 100-continue, don't flush yet
|
|
1056
|
+
if (this._expectContinue && !this._continueReceived) {
|
|
1057
|
+
return;
|
|
1058
|
+
}
|
|
1059
|
+
// Keep draining the queue as long as it has items
|
|
1060
|
+
// This handles writes that might happen while we are flushing (e.g. from callbacks)
|
|
1061
|
+
while (this._pendingWrites.length > 0) {
|
|
1062
|
+
const writes = this._pendingWrites;
|
|
1063
|
+
this._pendingWrites = [];
|
|
1064
|
+
for (const pending of writes) {
|
|
1065
|
+
// Call super._write (OutgoingMessage._write) directly
|
|
1066
|
+
super._write(pending.chunk, pending.encoding, pending.callback);
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
if (this._ended) {
|
|
1070
|
+
super.end();
|
|
1071
|
+
}
|
|
1025
1072
|
}
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
for (const pending of writes) {
|
|
1029
|
-
this._write(pending.chunk, pending.encoding, pending.callback);
|
|
1030
|
-
}
|
|
1031
|
-
if (this._ended) {
|
|
1032
|
-
this._finishRequest();
|
|
1073
|
+
finally {
|
|
1074
|
+
this._isFlushing = false;
|
|
1033
1075
|
}
|
|
1034
1076
|
}
|
|
1077
|
+
// Simplified _finishRequest - not needed as much if we call super.end() directly
|
|
1035
1078
|
_finishRequest() {
|
|
1036
|
-
if (
|
|
1037
|
-
|
|
1038
|
-
|
|
1079
|
+
if (this._connected && this._pendingWrites.length === 0) {
|
|
1080
|
+
super.end();
|
|
1081
|
+
}
|
|
1039
1082
|
}
|
|
1040
1083
|
_sendRequest() {
|
|
1041
1084
|
debugLog(`ClientRequest._sendRequest: headersSent=${this.headersSent}, socket=${!!this.socket}`);
|
|
@@ -1050,7 +1093,7 @@ export class ClientRequest extends OutgoingMessage {
|
|
|
1050
1093
|
}
|
|
1051
1094
|
_write(chunk, encoding, callback) {
|
|
1052
1095
|
this._hasBody = true;
|
|
1053
|
-
if (!this._connected) {
|
|
1096
|
+
if (!this._connected || this._isFlushing) {
|
|
1054
1097
|
this._pendingWrites.push({ chunk, encoding, callback });
|
|
1055
1098
|
return;
|
|
1056
1099
|
}
|
|
@@ -1060,39 +1103,46 @@ export class ClientRequest extends OutgoingMessage {
|
|
|
1060
1103
|
}
|
|
1061
1104
|
write(chunk, encoding, callback) {
|
|
1062
1105
|
this._hasBody = true;
|
|
1063
|
-
|
|
1106
|
+
// If not connected OR currently flushing, enqueue to preserve order
|
|
1107
|
+
if (!this._connected || this._isFlushing) {
|
|
1064
1108
|
this._pendingWrites.push({ chunk, encoding, callback });
|
|
1065
1109
|
return true;
|
|
1066
1110
|
}
|
|
1067
|
-
if (!this.headersSent)
|
|
1068
|
-
this._sendRequest();
|
|
1069
1111
|
return super.write(chunk, encoding, callback);
|
|
1070
1112
|
}
|
|
1071
1113
|
end(chunk, encoding, callback) {
|
|
1072
|
-
|
|
1073
|
-
|
|
1114
|
+
if (typeof chunk === 'function') {
|
|
1115
|
+
callback = chunk;
|
|
1116
|
+
chunk = null;
|
|
1117
|
+
encoding = null;
|
|
1118
|
+
}
|
|
1119
|
+
else if (typeof encoding === 'function') {
|
|
1120
|
+
callback = encoding;
|
|
1121
|
+
encoding = null;
|
|
1122
|
+
}
|
|
1123
|
+
debugLog(`ClientRequest.end() called, connected=${this._connected}, chunk=${!!chunk}`);
|
|
1124
|
+
if (chunk != null) {
|
|
1074
1125
|
this._hasBody = true;
|
|
1075
1126
|
if (!this.headersSent && !this.hasHeader('Content-Length')) {
|
|
1076
|
-
const len =
|
|
1127
|
+
const len = this._getPendingBodyLength() + this._getChunkByteLength(chunk, encoding);
|
|
1077
1128
|
this.setHeader('Content-Length', len);
|
|
1078
1129
|
}
|
|
1130
|
+
// Use this.write to handle pending queue if not connected
|
|
1079
1131
|
this.write(chunk, encoding);
|
|
1080
1132
|
}
|
|
1081
1133
|
this._ended = true;
|
|
1082
|
-
// If connected, we can send request and end immediately
|
|
1083
1134
|
if (this._connected) {
|
|
1084
|
-
if
|
|
1085
|
-
|
|
1135
|
+
// Only end if the queue is empty. _flushPendingWrites will handle it otherwise.
|
|
1136
|
+
if (this._pendingWrites.length === 0) {
|
|
1137
|
+
super.end(callback);
|
|
1138
|
+
}
|
|
1139
|
+
else if (callback) {
|
|
1140
|
+
this.once('finish', callback);
|
|
1086
1141
|
}
|
|
1087
|
-
// Call super.end only when connected
|
|
1088
|
-
super.end(callback);
|
|
1089
1142
|
}
|
|
1090
1143
|
else {
|
|
1091
|
-
|
|
1092
|
-
// Store callback if provided
|
|
1093
|
-
if (callback) {
|
|
1144
|
+
if (callback)
|
|
1094
1145
|
this.once('finish', callback);
|
|
1095
|
-
}
|
|
1096
1146
|
}
|
|
1097
1147
|
return this;
|
|
1098
1148
|
}
|
package/lib/net.d.ts
CHANGED
|
@@ -98,6 +98,7 @@ export declare class Socket extends Duplex {
|
|
|
98
98
|
autoSelectFamilyAttemptedAddresses: string[];
|
|
99
99
|
private _autoSelectFamily;
|
|
100
100
|
private _timeout;
|
|
101
|
+
private _nativeWriteCallbacks;
|
|
101
102
|
get localFamily(): string;
|
|
102
103
|
get readyState(): string;
|
|
103
104
|
get pending(): boolean;
|
|
@@ -113,9 +114,7 @@ export declare class Socket extends Duplex {
|
|
|
113
114
|
connect(options: any, connectionListener?: () => void): this;
|
|
114
115
|
private _connect;
|
|
115
116
|
private _connectUnix;
|
|
116
|
-
end(
|
|
117
|
-
end(chunk: any, cb?: () => void): this;
|
|
118
|
-
end(chunk: any, encoding: string, cb?: () => void): this;
|
|
117
|
+
end(chunk?: any, encoding?: any, cb?: any): this;
|
|
119
118
|
_write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
|
|
120
119
|
_read(size: number): void;
|
|
121
120
|
_final(callback: (error?: Error | null) => void): void;
|
package/lib/net.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"net.d.ts","sourceRoot":"","sources":["../src/net.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAI5C,OAAO,KAAK,EAAE,eAAe,EAAmB,SAAS,EAAE,MAAM,aAAa,CAAA;AAE9E,OAAO,EAAE,SAAS,EA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,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;CAGvE;AAMD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,kBAAkB,CAAC,EAAE,MAAM,IAAI,GAAG,MAAM,CAGtF;AAED,eAAO,MAAM,OAAO,yBAAmB,CAAC;AAExC,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,CAEjG;AAGD,OAAO,EACH,IAAI,EACJ,MAAM,EACN,MAAM,EACN,0BAA0B,EAC1B,0BAA0B,EAC1B,SAAS,EACT,UAAU,EACV,cAAc,GACjB,CAAC;AAEF,YAAY,EAAE,SAAS,EAAE,CAAC;;;;;;;;;;;;;;;;;AAE1B,wBAeE"}
|
package/lib/net.js
CHANGED
|
@@ -262,6 +262,7 @@ export class Socket extends Duplex {
|
|
|
262
262
|
this.autoSelectFamilyAttemptedAddresses = [];
|
|
263
263
|
this._autoSelectFamily = false;
|
|
264
264
|
this._timeout = 0;
|
|
265
|
+
this._nativeWriteCallbacks = [];
|
|
265
266
|
if (options?.socketDriver) {
|
|
266
267
|
// Wrapping existing socket (from Server)
|
|
267
268
|
this._driver = options.socketDriver;
|
|
@@ -269,9 +270,8 @@ export class Socket extends Duplex {
|
|
|
269
270
|
this._setupEvents();
|
|
270
271
|
// Enable noDelay by default
|
|
271
272
|
this._driver.setNoDelay(true);
|
|
272
|
-
//
|
|
273
|
-
|
|
274
|
-
// Emit connect for server-side socket? No, it's already connected.
|
|
273
|
+
// For accepted server sockets, defer resume until after the server
|
|
274
|
+
// emits 'connection' so user handlers can attach first.
|
|
275
275
|
}
|
|
276
276
|
else {
|
|
277
277
|
// New client socket
|
|
@@ -290,8 +290,8 @@ export class Socket extends Duplex {
|
|
|
290
290
|
return this;
|
|
291
291
|
}
|
|
292
292
|
const ret = super.on(event, listener);
|
|
293
|
-
if (event === 'data' &&
|
|
294
|
-
debugLog(`Socket on('data'), flowing: ${this.readableFlowing}`);
|
|
293
|
+
if (event === 'data' && this.readableFlowing !== true) {
|
|
294
|
+
debugLog(`Socket on('data'), flowing: ${this.readableFlowing}, paused: ${this.isPaused()}`);
|
|
295
295
|
this.resume();
|
|
296
296
|
}
|
|
297
297
|
return ret;
|
|
@@ -327,8 +327,10 @@ export class Socket extends Duplex {
|
|
|
327
327
|
if (data && data.byteLength > 0) {
|
|
328
328
|
const buffer = Buffer.from(data);
|
|
329
329
|
this.bytesRead += buffer.length;
|
|
330
|
-
|
|
331
|
-
|
|
330
|
+
this.push(buffer);
|
|
331
|
+
if (this.listenerCount('data') > 0 && this.readableFlowing !== true) {
|
|
332
|
+
debugLog(`Socket onEvent(DATA) restoring flowing mode for attached 'data' listeners`);
|
|
333
|
+
this.resume();
|
|
332
334
|
}
|
|
333
335
|
}
|
|
334
336
|
break;
|
|
@@ -355,6 +357,11 @@ export class Socket extends Duplex {
|
|
|
355
357
|
this._connected = false;
|
|
356
358
|
this.connecting = false;
|
|
357
359
|
this.push(null); // EOF
|
|
360
|
+
if (!this.allowHalfOpen && !this.writableEnded && !this.destroyed) {
|
|
361
|
+
// Match Node's default behavior: half-close the writable side
|
|
362
|
+
// when the peer finishes and allowHalfOpen is false.
|
|
363
|
+
this.end();
|
|
364
|
+
}
|
|
358
365
|
this.emit('close', this._hadError);
|
|
359
366
|
break;
|
|
360
367
|
case NetSocketEvent.DRAIN:
|
|
@@ -506,22 +513,39 @@ export class Socket extends Duplex {
|
|
|
506
513
|
return this;
|
|
507
514
|
}
|
|
508
515
|
end(chunk, encoding, cb) {
|
|
509
|
-
debugLog(`Socket (localPort: ${this.localPort}) .end() called`);
|
|
510
516
|
if (typeof chunk === 'function') {
|
|
511
|
-
|
|
517
|
+
cb = chunk;
|
|
518
|
+
chunk = null;
|
|
519
|
+
encoding = null;
|
|
512
520
|
}
|
|
513
|
-
else if (
|
|
514
|
-
|
|
521
|
+
else if (typeof encoding === 'function') {
|
|
522
|
+
cb = encoding;
|
|
523
|
+
encoding = null;
|
|
515
524
|
}
|
|
516
|
-
|
|
517
|
-
|
|
525
|
+
debugLog(`Socket (localPort: ${this.localPort}) .end() called`);
|
|
526
|
+
if (chunk != null) {
|
|
527
|
+
this.write(chunk, encoding);
|
|
518
528
|
}
|
|
529
|
+
super.end(cb);
|
|
519
530
|
return this;
|
|
520
531
|
}
|
|
521
532
|
_write(chunk, encoding, callback) {
|
|
522
533
|
if (!this._driver) {
|
|
523
534
|
return callback(new Error('Socket not connected'));
|
|
524
535
|
}
|
|
536
|
+
if (!this._connected && this.connecting) {
|
|
537
|
+
const onConnect = () => {
|
|
538
|
+
this.removeListener('error', onError);
|
|
539
|
+
this._write(chunk, encoding, callback);
|
|
540
|
+
};
|
|
541
|
+
const onError = (err) => {
|
|
542
|
+
this.removeListener('connect', onConnect);
|
|
543
|
+
callback(err);
|
|
544
|
+
};
|
|
545
|
+
this.once('connect', onConnect);
|
|
546
|
+
this.once('error', onError);
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
525
549
|
try {
|
|
526
550
|
const buffer = (chunk instanceof Buffer) ? chunk : Buffer.from(chunk, encoding);
|
|
527
551
|
this.bytesWritten += buffer.length;
|
|
@@ -539,9 +563,24 @@ export class Socket extends Duplex {
|
|
|
539
563
|
this._driver.resume();
|
|
540
564
|
}
|
|
541
565
|
_final(callback) {
|
|
542
|
-
if (this._driver) {
|
|
543
|
-
|
|
566
|
+
if (!this._driver) {
|
|
567
|
+
return callback(null);
|
|
568
|
+
}
|
|
569
|
+
if (!this._connected && this.connecting) {
|
|
570
|
+
const onConnect = () => {
|
|
571
|
+
this.removeListener('error', onError);
|
|
572
|
+
this._final(callback);
|
|
573
|
+
};
|
|
574
|
+
const onError = () => {
|
|
575
|
+
this.removeListener('connect', onConnect);
|
|
576
|
+
callback(null); // Already destroyed/errored
|
|
577
|
+
};
|
|
578
|
+
this.once('connect', onConnect);
|
|
579
|
+
this.once('error', onError);
|
|
580
|
+
return;
|
|
544
581
|
}
|
|
582
|
+
debugLog(`Socket (localPort: ${this.localPort}) ._final() called, shutting down driver`);
|
|
583
|
+
this._driver.shutdown();
|
|
545
584
|
callback(null);
|
|
546
585
|
}
|
|
547
586
|
destroy(reason) {
|
|
@@ -724,6 +763,9 @@ export class Server extends EventEmitter {
|
|
|
724
763
|
this._sockets.delete(socket);
|
|
725
764
|
});
|
|
726
765
|
this.emit('connection', socket);
|
|
766
|
+
// Start reading only after 'connection' handlers ran.
|
|
767
|
+
// This prevents dropping data when listeners are attached in the callback.
|
|
768
|
+
socket.resume();
|
|
727
769
|
}
|
|
728
770
|
}
|
|
729
771
|
break;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-net",
|
|
3
3
|
"description": "Ultra-high-performance networking to React Native by combining a memory-safe Rust core with the zero-overhead Nitro Modules JSI bridge. Provides Node.js-compatible net, tls, http(s) API.",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"module": "./lib/index.js",
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/node": "*",
|
|
44
44
|
"@types/readable-stream": "^4.0.23",
|
|
45
|
-
"react-native-nitro-modules": "0.35.0",
|
|
45
|
+
"react-native-nitro-modules": "^0.35.0",
|
|
46
46
|
"typescript": "^5.3.3"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"react-native": "*",
|
|
50
|
-
"react-native-nitro-modules": "0.35.0"
|
|
50
|
+
"react-native-nitro-modules": "^0.35.0"
|
|
51
51
|
},
|
|
52
52
|
"packageManager": "yarn@4.12.0",
|
|
53
53
|
"files": [
|
package/src/http.ts
CHANGED
|
@@ -289,8 +289,16 @@ export class OutgoingMessage extends Writable {
|
|
|
289
289
|
}
|
|
290
290
|
|
|
291
291
|
end(chunk?: any, encoding?: any, callback?: any): this {
|
|
292
|
-
|
|
293
|
-
|
|
292
|
+
if (typeof chunk === 'function') {
|
|
293
|
+
callback = chunk;
|
|
294
|
+
chunk = null;
|
|
295
|
+
encoding = null;
|
|
296
|
+
} else if (typeof encoding === 'function') {
|
|
297
|
+
callback = encoding;
|
|
298
|
+
encoding = null;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (chunk != null) {
|
|
294
302
|
this.write(chunk, encoding);
|
|
295
303
|
}
|
|
296
304
|
super.end(callback);
|
|
@@ -362,24 +370,31 @@ export class ServerResponse extends OutgoingMessage {
|
|
|
362
370
|
}
|
|
363
371
|
|
|
364
372
|
end(chunk?: any, encoding?: any, callback?: any): this {
|
|
373
|
+
if (typeof chunk === 'function') {
|
|
374
|
+
callback = chunk;
|
|
375
|
+
chunk = null;
|
|
376
|
+
encoding = null;
|
|
377
|
+
} else if (typeof encoding === 'function') {
|
|
378
|
+
callback = encoding;
|
|
379
|
+
encoding = null;
|
|
380
|
+
}
|
|
381
|
+
|
|
365
382
|
if (!this.headersSent) {
|
|
366
383
|
// If we have a single chunk and no headers sent yet, we can add Content-Length
|
|
367
384
|
// to avoid chunked encoding for simple responses.
|
|
368
|
-
if (chunk) {
|
|
369
|
-
const len = typeof chunk === 'string' ? Buffer.byteLength(chunk, encoding) : chunk.length;
|
|
385
|
+
if (chunk != null) {
|
|
386
|
+
const len = typeof chunk === 'string' ? Buffer.byteLength(chunk, (encoding as string) || undefined) : chunk.length;
|
|
370
387
|
this.setHeader('Content-Length', len);
|
|
371
|
-
} else {
|
|
388
|
+
} else if (!this.hasHeader('Transfer-Encoding')) {
|
|
372
389
|
this.setHeader('Content-Length', 0);
|
|
373
390
|
}
|
|
374
391
|
this._sendResponseHeaders();
|
|
375
392
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
super.end(callback);
|
|
380
|
-
} else {
|
|
381
|
-
super.end(chunk, encoding, callback);
|
|
393
|
+
|
|
394
|
+
if (chunk != null) {
|
|
395
|
+
this.write(chunk, encoding);
|
|
382
396
|
}
|
|
397
|
+
super.end(callback);
|
|
383
398
|
return this;
|
|
384
399
|
}
|
|
385
400
|
}
|
|
@@ -954,6 +969,25 @@ export class ClientRequest extends OutgoingMessage {
|
|
|
954
969
|
private _expectContinue: boolean = false;
|
|
955
970
|
private _continueReceived: boolean = false;
|
|
956
971
|
|
|
972
|
+
private _getChunkByteLength(chunk: any, encoding?: string | null): number {
|
|
973
|
+
if (chunk == null) return 0;
|
|
974
|
+
const normalizedEncoding = typeof encoding === 'string' ? encoding : undefined;
|
|
975
|
+
if (typeof chunk === 'string') {
|
|
976
|
+
return Buffer.byteLength(chunk, normalizedEncoding as BufferEncoding | undefined);
|
|
977
|
+
}
|
|
978
|
+
if (typeof chunk.length === 'number') {
|
|
979
|
+
return chunk.length;
|
|
980
|
+
}
|
|
981
|
+
const buffer = Buffer.from(chunk, normalizedEncoding as BufferEncoding | undefined);
|
|
982
|
+
return buffer.length;
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
private _getPendingBodyLength(): number {
|
|
986
|
+
return this._pendingWrites.reduce((total, pending) => {
|
|
987
|
+
return total + this._getChunkByteLength(pending.chunk, pending.encoding);
|
|
988
|
+
}, 0);
|
|
989
|
+
}
|
|
990
|
+
|
|
957
991
|
constructor(options: RequestOptions, callback?: (res: IncomingMessage) => void) {
|
|
958
992
|
super();
|
|
959
993
|
this._options = options;
|
|
@@ -1171,28 +1205,43 @@ export class ClientRequest extends OutgoingMessage {
|
|
|
1171
1205
|
this.emit('close');
|
|
1172
1206
|
}
|
|
1173
1207
|
|
|
1208
|
+
private _isFlushing = false;
|
|
1174
1209
|
private _flushPendingWrites() {
|
|
1175
|
-
if (!this.socket) return;
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1210
|
+
if (!this.socket || this._isFlushing) return;
|
|
1211
|
+
|
|
1212
|
+
this._isFlushing = true;
|
|
1213
|
+
try {
|
|
1214
|
+
if (!this.headersSent) this._sendRequest();
|
|
1215
|
+
|
|
1216
|
+
// If we are waiting for 100-continue, don't flush yet
|
|
1217
|
+
if (this._expectContinue && !this._continueReceived) {
|
|
1218
|
+
return;
|
|
1219
|
+
}
|
|
1182
1220
|
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1221
|
+
// Keep draining the queue as long as it has items
|
|
1222
|
+
// This handles writes that might happen while we are flushing (e.g. from callbacks)
|
|
1223
|
+
while (this._pendingWrites.length > 0) {
|
|
1224
|
+
const writes = this._pendingWrites;
|
|
1225
|
+
this._pendingWrites = [];
|
|
1226
|
+
for (const pending of writes) {
|
|
1227
|
+
// Call super._write (OutgoingMessage._write) directly
|
|
1228
|
+
super._write(pending.chunk, pending.encoding, pending.callback);
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
if (this._ended) {
|
|
1233
|
+
super.end();
|
|
1234
|
+
}
|
|
1235
|
+
} finally {
|
|
1236
|
+
this._isFlushing = false;
|
|
1190
1237
|
}
|
|
1191
1238
|
}
|
|
1192
1239
|
|
|
1240
|
+
// Simplified _finishRequest - not needed as much if we call super.end() directly
|
|
1193
1241
|
private _finishRequest() {
|
|
1194
|
-
if (
|
|
1195
|
-
|
|
1242
|
+
if (this._connected && this._pendingWrites.length === 0) {
|
|
1243
|
+
super.end();
|
|
1244
|
+
}
|
|
1196
1245
|
}
|
|
1197
1246
|
|
|
1198
1247
|
private _sendRequest() {
|
|
@@ -1210,7 +1259,7 @@ export class ClientRequest extends OutgoingMessage {
|
|
|
1210
1259
|
|
|
1211
1260
|
_write(chunk: any, encoding: string, callback: (error?: Error | null) => void) {
|
|
1212
1261
|
this._hasBody = true;
|
|
1213
|
-
if (!this._connected) {
|
|
1262
|
+
if (!this._connected || this._isFlushing) {
|
|
1214
1263
|
this._pendingWrites.push({ chunk, encoding, callback });
|
|
1215
1264
|
return;
|
|
1216
1265
|
}
|
|
@@ -1220,39 +1269,47 @@ export class ClientRequest extends OutgoingMessage {
|
|
|
1220
1269
|
|
|
1221
1270
|
write(chunk: any, encoding?: any, callback?: any): boolean {
|
|
1222
1271
|
this._hasBody = true;
|
|
1223
|
-
|
|
1272
|
+
// If not connected OR currently flushing, enqueue to preserve order
|
|
1273
|
+
if (!this._connected || this._isFlushing) {
|
|
1224
1274
|
this._pendingWrites.push({ chunk, encoding, callback });
|
|
1225
1275
|
return true;
|
|
1226
1276
|
}
|
|
1227
|
-
if (!this.headersSent) this._sendRequest();
|
|
1228
1277
|
return super.write(chunk, encoding, callback);
|
|
1229
1278
|
}
|
|
1230
1279
|
|
|
1231
1280
|
end(chunk?: any, encoding?: any, callback?: any): this {
|
|
1232
|
-
|
|
1233
|
-
|
|
1281
|
+
if (typeof chunk === 'function') {
|
|
1282
|
+
callback = chunk;
|
|
1283
|
+
chunk = null;
|
|
1284
|
+
encoding = null;
|
|
1285
|
+
} else if (typeof encoding === 'function') {
|
|
1286
|
+
callback = encoding;
|
|
1287
|
+
encoding = null;
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
debugLog(`ClientRequest.end() called, connected=${this._connected}, chunk=${!!chunk}`);
|
|
1291
|
+
|
|
1292
|
+
if (chunk != null) {
|
|
1234
1293
|
this._hasBody = true;
|
|
1235
1294
|
if (!this.headersSent && !this.hasHeader('Content-Length')) {
|
|
1236
|
-
const len =
|
|
1295
|
+
const len = this._getPendingBodyLength() + this._getChunkByteLength(chunk, encoding as string | undefined);
|
|
1237
1296
|
this.setHeader('Content-Length', len);
|
|
1238
1297
|
}
|
|
1298
|
+
// Use this.write to handle pending queue if not connected
|
|
1239
1299
|
this.write(chunk, encoding);
|
|
1240
1300
|
}
|
|
1301
|
+
|
|
1241
1302
|
this._ended = true;
|
|
1242
1303
|
|
|
1243
|
-
// If connected, we can send request and end immediately
|
|
1244
1304
|
if (this._connected) {
|
|
1245
|
-
if
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
super.end(callback);
|
|
1250
|
-
} else {
|
|
1251
|
-
// Socket not connected yet - _flushPendingWrites will handle ending
|
|
1252
|
-
// Store callback if provided
|
|
1253
|
-
if (callback) {
|
|
1305
|
+
// Only end if the queue is empty. _flushPendingWrites will handle it otherwise.
|
|
1306
|
+
if (this._pendingWrites.length === 0) {
|
|
1307
|
+
super.end(callback);
|
|
1308
|
+
} else if (callback) {
|
|
1254
1309
|
this.once('finish', callback);
|
|
1255
1310
|
}
|
|
1311
|
+
} else {
|
|
1312
|
+
if (callback) this.once('finish', callback);
|
|
1256
1313
|
}
|
|
1257
1314
|
return this;
|
|
1258
1315
|
}
|
package/src/net.ts
CHANGED
|
@@ -296,6 +296,7 @@ export class Socket extends Duplex {
|
|
|
296
296
|
public autoSelectFamilyAttemptedAddresses: string[] = [];
|
|
297
297
|
private _autoSelectFamily: boolean = false;
|
|
298
298
|
private _timeout: number = 0;
|
|
299
|
+
private _nativeWriteCallbacks: Array<(error?: Error | null) => void> = [];
|
|
299
300
|
|
|
300
301
|
get localFamily(): string {
|
|
301
302
|
return this.localAddress && this.localAddress.includes(':') ? 'IPv6' : 'IPv4';
|
|
@@ -333,9 +334,8 @@ export class Socket extends Duplex {
|
|
|
333
334
|
this._setupEvents();
|
|
334
335
|
// Enable noDelay by default
|
|
335
336
|
this._driver.setNoDelay(true);
|
|
336
|
-
//
|
|
337
|
-
|
|
338
|
-
// Emit connect for server-side socket? No, it's already connected.
|
|
337
|
+
// For accepted server sockets, defer resume until after the server
|
|
338
|
+
// emits 'connection' so user handlers can attach first.
|
|
339
339
|
} else {
|
|
340
340
|
// New client socket
|
|
341
341
|
ensureInitialized();
|
|
@@ -355,8 +355,8 @@ export class Socket extends Duplex {
|
|
|
355
355
|
return this;
|
|
356
356
|
}
|
|
357
357
|
const ret = super.on(event, listener);
|
|
358
|
-
if (event === 'data' &&
|
|
359
|
-
debugLog(`Socket on('data'), flowing: ${(this as any).readableFlowing}`);
|
|
358
|
+
if (event === 'data' && (this as any).readableFlowing !== true) {
|
|
359
|
+
debugLog(`Socket on('data'), flowing: ${(this as any).readableFlowing}, paused: ${this.isPaused()}`);
|
|
360
360
|
this.resume();
|
|
361
361
|
}
|
|
362
362
|
return ret;
|
|
@@ -392,8 +392,10 @@ export class Socket extends Duplex {
|
|
|
392
392
|
if (data && data.byteLength > 0) {
|
|
393
393
|
const buffer = Buffer.from(data);
|
|
394
394
|
this.bytesRead += buffer.length;
|
|
395
|
-
|
|
396
|
-
|
|
395
|
+
this.push(buffer);
|
|
396
|
+
if (this.listenerCount('data') > 0 && (this as any).readableFlowing !== true) {
|
|
397
|
+
debugLog(`Socket onEvent(DATA) restoring flowing mode for attached 'data' listeners`);
|
|
398
|
+
this.resume();
|
|
397
399
|
}
|
|
398
400
|
}
|
|
399
401
|
break;
|
|
@@ -422,6 +424,11 @@ export class Socket extends Duplex {
|
|
|
422
424
|
this._connected = false;
|
|
423
425
|
this.connecting = false;
|
|
424
426
|
this.push(null); // EOF
|
|
427
|
+
if (!(this as any).allowHalfOpen && !this.writableEnded && !this.destroyed) {
|
|
428
|
+
// Match Node's default behavior: half-close the writable side
|
|
429
|
+
// when the peer finishes and allowHalfOpen is false.
|
|
430
|
+
this.end();
|
|
431
|
+
}
|
|
425
432
|
this.emit('close', this._hadError);
|
|
426
433
|
break;
|
|
427
434
|
case NetSocketEvent.DRAIN:
|
|
@@ -582,18 +589,20 @@ export class Socket extends Duplex {
|
|
|
582
589
|
return this;
|
|
583
590
|
}
|
|
584
591
|
|
|
585
|
-
end(cb?: () => void): this;
|
|
586
|
-
end(chunk: any, cb?: () => void): this;
|
|
587
|
-
end(chunk: any, encoding: string, cb?: () => void): this;
|
|
588
592
|
end(chunk?: any, encoding?: any, cb?: any): this {
|
|
589
|
-
debugLog(`Socket (localPort: ${this.localPort}) .end() called`);
|
|
590
593
|
if (typeof chunk === 'function') {
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
} else {
|
|
595
|
-
|
|
594
|
+
cb = chunk;
|
|
595
|
+
chunk = null;
|
|
596
|
+
encoding = null;
|
|
597
|
+
} else if (typeof encoding === 'function') {
|
|
598
|
+
cb = encoding;
|
|
599
|
+
encoding = null;
|
|
596
600
|
}
|
|
601
|
+
debugLog(`Socket (localPort: ${this.localPort}) .end() called`);
|
|
602
|
+
if (chunk != null) {
|
|
603
|
+
this.write(chunk, encoding);
|
|
604
|
+
}
|
|
605
|
+
super.end(cb);
|
|
597
606
|
return this;
|
|
598
607
|
}
|
|
599
608
|
|
|
@@ -601,6 +610,19 @@ export class Socket extends Duplex {
|
|
|
601
610
|
if (!this._driver) {
|
|
602
611
|
return callback(new Error('Socket not connected'));
|
|
603
612
|
}
|
|
613
|
+
if (!this._connected && this.connecting) {
|
|
614
|
+
const onConnect = () => {
|
|
615
|
+
this.removeListener('error', onError);
|
|
616
|
+
this._write(chunk, encoding, callback);
|
|
617
|
+
};
|
|
618
|
+
const onError = (err: Error) => {
|
|
619
|
+
this.removeListener('connect', onConnect);
|
|
620
|
+
callback(err);
|
|
621
|
+
};
|
|
622
|
+
this.once('connect', onConnect);
|
|
623
|
+
this.once('error', onError);
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
604
626
|
try {
|
|
605
627
|
const buffer = (chunk instanceof Buffer) ? chunk : Buffer.from(chunk, encoding as any);
|
|
606
628
|
this.bytesWritten += buffer.length;
|
|
@@ -618,9 +640,24 @@ export class Socket extends Duplex {
|
|
|
618
640
|
}
|
|
619
641
|
|
|
620
642
|
_final(callback: (error?: Error | null) => void): void {
|
|
621
|
-
if (this._driver) {
|
|
622
|
-
|
|
643
|
+
if (!this._driver) {
|
|
644
|
+
return callback(null);
|
|
645
|
+
}
|
|
646
|
+
if (!this._connected && this.connecting) {
|
|
647
|
+
const onConnect = () => {
|
|
648
|
+
this.removeListener('error', onError);
|
|
649
|
+
this._final(callback);
|
|
650
|
+
};
|
|
651
|
+
const onError = () => {
|
|
652
|
+
this.removeListener('connect', onConnect);
|
|
653
|
+
callback(null); // Already destroyed/errored
|
|
654
|
+
};
|
|
655
|
+
this.once('connect', onConnect);
|
|
656
|
+
this.once('error', onError);
|
|
657
|
+
return;
|
|
623
658
|
}
|
|
659
|
+
debugLog(`Socket (localPort: ${this.localPort}) ._final() called, shutting down driver`);
|
|
660
|
+
this._driver.shutdown();
|
|
624
661
|
callback(null);
|
|
625
662
|
}
|
|
626
663
|
|
|
@@ -832,6 +869,9 @@ export class Server extends EventEmitter {
|
|
|
832
869
|
this._sockets.delete(socket);
|
|
833
870
|
});
|
|
834
871
|
this.emit('connection', socket);
|
|
872
|
+
// Start reading only after 'connection' handlers ran.
|
|
873
|
+
// This prevents dropping data when listeners are attached in the callback.
|
|
874
|
+
socket.resume();
|
|
835
875
|
}
|
|
836
876
|
}
|
|
837
877
|
break;
|