Skip to content

Commit d347f3b

Browse files
committed
fix(packages/bindings#write): do not call native binding for empty buffers
1 parent f70d672 commit d347f3b

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

packages/bindings/lib/darwin.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,16 @@ class DarwinBinding extends AbstractBinding {
5959
}
6060

6161
write(buffer) {
62-
this.writeOperation = super
63-
.write(buffer)
64-
.then(() => unixWrite.call(this, buffer))
65-
.then(() => {
66-
this.writeOperation = null
67-
})
68-
return this.writeOperation
62+
if (buffer.length > 0) {
63+
this.writeOperation = super
64+
.write(buffer)
65+
.then(() => unixWrite.call(this, buffer))
66+
.then(() => {
67+
this.writeOperation = null
68+
})
69+
return this.writeOperation
70+
}
71+
return Promise.resolve()
6972
}
7073

7174
update(options) {

packages/bindings/lib/linux.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,16 @@ class LinuxBinding extends AbstractBinding {
5959
}
6060

6161
write(buffer) {
62-
this.writeOperation = super
63-
.write(buffer)
64-
.then(() => unixWrite.call(this, buffer))
65-
.then(() => {
66-
this.writeOperation = null
67-
})
68-
return this.writeOperation
62+
if (buffer.length > 0) {
63+
this.writeOperation = super
64+
.write(buffer)
65+
.then(() => unixWrite.call(this, buffer))
66+
.then(() => {
67+
this.writeOperation = null
68+
})
69+
return this.writeOperation
70+
}
71+
return Promise.resolve()
6972
}
7073

7174
update(options) {

packages/bindings/lib/win32.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,16 @@ class WindowsBinding extends AbstractBinding {
6666
}
6767

6868
write(buffer) {
69-
this.writeOperation = super
70-
.write(buffer)
71-
.then(() => promisify(binding.write)(this.fd, buffer))
72-
.then(() => {
73-
this.writeOperation = null
74-
})
75-
return this.writeOperation
69+
if (buffer.length > 0) {
70+
this.writeOperation = super
71+
.write(buffer)
72+
.then(() => promisify(binding.write)(this.fd, buffer))
73+
.then(() => {
74+
this.writeOperation = null
75+
})
76+
return this.writeOperation
77+
}
78+
return Promise.resolve()
7679
}
7780

7881
update(options) {

0 commit comments

Comments
 (0)