Skip to content

Commit

Permalink
update uwebsocket.js
Browse files Browse the repository at this point in the history
  • Loading branch information
tinchoz49 committed Mar 8, 2024
1 parent 8ef8273 commit dfbc7f4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"nanoerror": "^2.0.0",
"streamx": "^2.12.5",
"tempy": "^1.0.1",
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.33.0"
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.42.0"
},
"devDependencies": {
"@types/events": "^3.0.2",
Expand Down
62 changes: 31 additions & 31 deletions src/http-socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,39 +55,37 @@ function onWrite (data, cb) {

this[kReadyState].write = true

if (this[kHead]) {
writeHead(res, this[kHead])
this[kHead] = null
}
res.cork(() => {
if (this[kHead]) {
writeHead(res, this[kHead])
this[kHead] = null
}

const drained = res.write(getChunk(data))
if (drained) {
this.bytesWritten += byteLength(data)
return cb()
}
drain(this, res, data, cb)
}
const drained = res.write(getChunk(data))
if (drained) {
this.bytesWritten += byteLength(data)
return cb()
}

function cork (res, data) {
writeHead(res, this[kHead])
this[kHead] = null
res.end(data)
drain(this, res, data, cb)
})
}

function end (socket, data) {
socket._clearTimeout()

const res = socket[kRes]

if (socket[kHead]) {
res.cork(cork.bind(socket, res, getChunk(data)))
} else {
res.cork(() => {
if (socket[kHead]) {
writeHead(res, socket[kHead])
socket[kHead] = null
}
res.end(getChunk(data))
}

socket.bytesWritten += byteLength(data)
socket.emit('close')
socket.emit('finish')
socket.bytesWritten += byteLength(data)
socket.emit('close')
socket.emit('finish')
})
}

function drain (socket, res, data, cb) {
Expand All @@ -105,14 +103,16 @@ function drain (socket, res, data, cb) {
const onDrain = () => {
if (done) return

done = res.write(getChunk(data))
if (done) {
socket.writableNeedDrain = false
this.bytesWritten += byteLength(data)
socket.removeListener('close', onClose)
socket.removeListener('drain', onDrain)
cb()
}
res.cork(() => {
done = res.write(getChunk(data))
if (done) {
socket.writableNeedDrain = false
this.bytesWritten += byteLength(data)
socket.removeListener('close', onClose)
socket.removeListener('drain', onDrain)
cb()
}
})
}

socket.on('drain', onDrain)
Expand Down

0 comments on commit dfbc7f4

Please sign in to comment.