aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/net.exports.js
diff options
context:
space:
mode:
authorGravatar Dylan Conway <dylan.conway567@gmail.com> 2023-01-12 19:10:41 -0800
committerGravatar Dylan Conway <dylan.conway567@gmail.com> 2023-01-12 19:10:41 -0800
commit766f8ceebc76dd749ba5c104f802c7ebda289db9 (patch)
treef84ee560938188261f7f5604a65b83aae354a646 /src/bun.js/net.exports.js
parentc03f7c998dd22689412658177e3a5736ce6b9034 (diff)
parent32f8cb31be6fb5b0b9aea1c6d4e95d118e8ef816 (diff)
downloadbun-766f8ceebc76dd749ba5c104f802c7ebda289db9.tar.gz
bun-766f8ceebc76dd749ba5c104f802c7ebda289db9.tar.zst
bun-766f8ceebc76dd749ba5c104f802c7ebda289db9.zip
Merge branch 'main' into dylan/github-dependencies
Diffstat (limited to 'src/bun.js/net.exports.js')
-rw-r--r--src/bun.js/net.exports.js21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/bun.js/net.exports.js b/src/bun.js/net.exports.js
index 8d283dd1e..f894cd5fa 100644
--- a/src/bun.js/net.exports.js
+++ b/src/bun.js/net.exports.js
@@ -86,11 +86,10 @@ export const Socket = (function (InternalSocket) {
self.emit("error", error);
},
- data(socket, buffer) {
- const self = socket.data;
- self.bytesRead += buffer.length;
+ data({ data: self }, { length, buffer }) {
+ self.bytesRead += length;
const queue = self.#readQueue;
- const ret = new Buffer(buffer.buffer);
+ const ret = new Buffer(buffer);
if (queue.isEmpty()) {
if (self.push(ret)) return;
}
@@ -197,7 +196,10 @@ export const Socket = (function (InternalSocket) {
connect(port, host, connectListener) {
// TODO support IPC sockets
var path;
- if (typeof host == "function") {
+ if (arguments.length === 1 && typeof port === "string") {
+ path = port;
+ port = undefined;
+ } else if (typeof host == "function") {
if (typeof port === "string") {
path = port;
port = undefined;
@@ -336,7 +338,14 @@ export const Socket = (function (InternalSocket) {
} else if (this.#writeCallback) {
callback(new Error("overlapping _write()"));
} else {
- if (written > 0) chunk = chunk.slice(written);
+ if (written > 0) {
+ if (typeof chunk == "string") {
+ chunk = chunk.slice(written);
+ } else {
+ chunk = chunk.subarray(written);
+ }
+ }
+
this.#writeCallback = callback;
this.#writeChunk = chunk;
}