Skip to content

Commit

Permalink
fix _write and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cirospaciari committed Jul 3, 2023
1 parent 6ba1191 commit 37f6cd4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/js/node/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ const Socket = (function (InternalSocket) {
}

_write(chunk, encoding, callback) {
if (typeof chunk == "string" && encoding !== "utf8") chunk = Buffer.from(chunk, encoding);
if (typeof chunk == "string" && encoding !== "ascii") chunk = Buffer.from(chunk, encoding);
var written = this[bunSocketInternal]?.write(chunk);
if (written == chunk.length) {
callback();
Expand Down
18 changes: 12 additions & 6 deletions src/js/node/tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,11 @@ const TLSSocket = (function (InternalTLSSocket) {

constructor(options) {
super(options);
if (options?.ALPNProtocols) {
convertALPNProtocols(options.ALPNProtocols, this);
if (options) {
const { ALPNProtocols } = options;
if (ALPNProtocols) {
convertALPNProtocols(ALPNProtocols, this);
}
}
this.#secureContext = options.secureContext || createSecureContext(options);
this.authorized = false;
Expand Down Expand Up @@ -438,8 +441,10 @@ class Server extends NetServer {
options = options.context;
}
if (options) {
if (options.ALPNProtocols) {
convertALPNProtocols(options.ALPNProtocols, this);
const { ALPNProtocols } = options;

if (ALPNProtocols) {
convertALPNProtocols(ALPNProtocols, this);
}

let key = options.key;
Expand Down Expand Up @@ -544,8 +549,9 @@ const CLIENT_RENEG_LIMIT = 3,
createConnection = (port, host, connectListener) => {
if (typeof port === "object") {
port.checkServerIdentity || checkServerIdentity;
if (port.ALPNProtocols) {
convertALPNProtocols(port.ALPNProtocols, port);
const { ALPNProtocols } = port;
if (ALPNProtocols) {
convertALPNProtocols(ALPNProtocols, port);
}
// port is option pass Socket options and let connect handle connection options
return new TLSSocket(port).connect(port, host, connectListener);
Expand Down
6 changes: 5 additions & 1 deletion src/js/out/modules/node/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ var isIPv4 = function(s) {
unix: path,
socket: Socket2.#Handlers,
tls
}).catch((error) => {
this.emit("error", error);
});
else
bunConnect({
Expand All @@ -291,6 +293,8 @@ var isIPv4 = function(s) {
port,
socket: Socket2.#Handlers,
tls
}).catch((error) => {
this.emit("error", error);
});
return this;
}
Expand Down Expand Up @@ -356,7 +360,7 @@ var isIPv4 = function(s) {
this[bunSocketInternal]?.unref();
}
_write(chunk, encoding, callback) {
if (typeof chunk == "string" && encoding !== "utf8")
if (typeof chunk == "string" && encoding !== "ascii")
chunk = Buffer.from(chunk, encoding);
var written = this[bunSocketInternal]?.write(chunk);
if (written == chunk.length)
Expand Down
18 changes: 12 additions & 6 deletions src/js/out/modules/node/tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,11 @@ var createServer = function(options, connectionListener) {
ALPNProtocols;
constructor(options) {
super(options);
if (options?.ALPNProtocols)
convertALPNProtocols(options.ALPNProtocols, this);
if (options) {
const { ALPNProtocols } = options;
if (ALPNProtocols)
convertALPNProtocols(ALPNProtocols, this);
}
this.#secureContext = options.secureContext || createSecureContext(options), this.authorized = !1, this.secureConnecting = !0, this._secureEstablished = !1, this._securePending = !0;
}
_secureEstablished = !1;
Expand Down Expand Up @@ -267,8 +270,9 @@ class Server extends NetServer {
if (options instanceof InternalSecureContext)
options = options.context;
if (options) {
if (options.ALPNProtocols)
convertALPNProtocols(options.ALPNProtocols, this);
const { ALPNProtocols } = options;
if (ALPNProtocols)
convertALPNProtocols(ALPNProtocols, this);
let key = options.key;
if (key) {
if (!isValidTLSArray(key))
Expand Down Expand Up @@ -337,8 +341,10 @@ class Server extends NetServer {
}
var CLIENT_RENEG_LIMIT = 3, CLIENT_RENEG_WINDOW = 600, DEFAULT_ECDH_CURVE = "auto", DEFAULT_CIPHERS = "DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256", DEFAULT_MIN_VERSION = "TLSv1.2", DEFAULT_MAX_VERSION = "TLSv1.3", createConnection = (port, host2, connectListener) => {
if (typeof port === "object") {
if (port.checkServerIdentity, port.ALPNProtocols)
convertALPNProtocols(port.ALPNProtocols, port);
port.checkServerIdentity;
const { ALPNProtocols } = port;
if (ALPNProtocols)
convertALPNProtocols(ALPNProtocols, port);
return new TLSSocket(port).connect(port, host2, connectListener);
}
return new TLSSocket().connect(port, host2, connectListener);
Expand Down

0 comments on commit 37f6cd4

Please sign in to comment.