Commit 0da311ce authored by wescoeur's avatar wescoeur Committed by Fabrice Marsaud

Avoid STATUS_PENDING error with SmbWritableStream.

parent bc313adc
......@@ -7,6 +7,18 @@ const requestAsync = Bluebird.promisify(request)
const maxPacketSize = new Bigint(8, 0x00010000 - 0x71)
function * fibonacci () {
let a = 1
let b = 2
for (;;) {
const c = a
a = b
b = c + a
yield c
}
}
class SmbWritableStream extends Writable {
constructor (connection, file, options = {}) {
super(options)
......@@ -32,11 +44,29 @@ class SmbWritableStream extends Writable {
chunk = chunk.slice(packetSize)
const offset = new Bigint(this.offset)
this.offset = this.offset.add(packetSize)
await requestAsync('write', {
FileId: this.file.FileId,
Offset: offset.toBuffer(),
Buffer: packet
}, this.connection)
const fiboGen = fibonacci()
let pending = true
while (pending) {
try {
await requestAsync('write', {
FileId: this.file.FileId,
Offset: offset.toBuffer(),
Buffer: packet
}, this.connection)
pending = false
} catch (error) {
if (error.code === 'STATUS_PENDING') {
await new Promise((resolve, reject) => {
setTimeout(resolve, fiboGen.next().value)
})
} else {
throw error
}
}
}
}
next()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment