mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
add _onTimeout
This commit is contained in:
@@ -2860,6 +2860,13 @@ fn NewSocket(comptime ssl: bool) type {
|
||||
return JSC.JSValue.jsNumber(this.bytes_written + this.buffered_data_for_node_net.len);
|
||||
}
|
||||
|
||||
pub fn getBufferedAmount(
|
||||
this: *This,
|
||||
_: *JSC.JSGlobalObject,
|
||||
) JSValue {
|
||||
return JSC.JSValue.jsNumber(this.buffered_data_for_node_net.len);
|
||||
}
|
||||
|
||||
pub fn getALPNProtocol(
|
||||
this: *This,
|
||||
globalObject: *JSC.JSGlobalObject,
|
||||
|
||||
@@ -369,7 +369,7 @@ pub fn getHasBody(this: *const NodeHTTPResponse, _: *JSC.JSGlobalObject) JSC.JSV
|
||||
|
||||
pub fn getBufferedAmount(this: *const NodeHTTPResponse, _: *JSC.JSGlobalObject) JSC.JSValue {
|
||||
if (this.flags.request_has_completed or this.flags.socket_closed) {
|
||||
return JSC.JSValue.jsNull();
|
||||
return JSC.JSValue.jsNumber(0);
|
||||
}
|
||||
|
||||
return JSC.JSValue.jsNumber(this.raw_response.getBufferedAmount());
|
||||
|
||||
@@ -91,6 +91,9 @@ function generate(ssl) {
|
||||
bytesWritten: {
|
||||
getter: "getBytesWritten",
|
||||
},
|
||||
bufferedAmount: {
|
||||
getter: "getBufferedAmount",
|
||||
},
|
||||
setNoDelay: {
|
||||
fn: "setNoDelay",
|
||||
length: 1,
|
||||
|
||||
@@ -379,14 +379,19 @@ const NodeHTTPServerSocket = class Socket extends Duplex {
|
||||
$isCallable(closeCallback) && closeCallback();
|
||||
}
|
||||
|
||||
_onTimeout = function () {
|
||||
_onTimeout() {
|
||||
const handle = this[kHandle];
|
||||
const response = handle?.response;
|
||||
// if there is a response, and it has pending data,
|
||||
// we suppress the timeout because a write is in progress
|
||||
if (response && response.getBufferedAmount() > 0) {
|
||||
return;
|
||||
}
|
||||
this.emit("timeout");
|
||||
};
|
||||
}
|
||||
_unrefTimer() {
|
||||
// for compatibility
|
||||
}
|
||||
|
||||
address() {
|
||||
return this[kHandle]?.remoteAddress || null;
|
||||
|
||||
@@ -587,6 +587,22 @@ Socket.prototype.address = function address() {
|
||||
};
|
||||
};
|
||||
|
||||
Socket.prototype._onTimeout = function () {
|
||||
// if there is pending data, write is in progress
|
||||
// so we suppress the timeout
|
||||
if (this._pendingData) {
|
||||
return;
|
||||
}
|
||||
|
||||
const handle = this._handle;
|
||||
// if there is a handle, and it has pending data,
|
||||
// we suppress the timeout because a write is in progress
|
||||
if (handle && handle.bufferedAmount > 0) {
|
||||
return;
|
||||
}
|
||||
this.emit("timeout");
|
||||
};
|
||||
|
||||
Object.defineProperty(Socket.prototype, "bufferSize", {
|
||||
get: function () {
|
||||
return this.writableLength;
|
||||
|
||||
Reference in New Issue
Block a user