-
-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
moving from readable-streams to streamx #42
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,10 @@ const events = require('events') | |
const dns = require('dns') | ||
const set = require('unordered-set') | ||
|
||
const EMPTY = Buffer.alloc(0) | ||
|
||
module.exports = UTP | ||
|
||
const EMPTY = Buffer.alloc(0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh my , i readded the EMPTY constant at the wrong place. Should be just as before. (memo) |
||
|
||
function UTP (opts) { | ||
if (!(this instanceof UTP)) return new UTP(opts) | ||
events.EventEmitter.call(this) | ||
|
@@ -132,16 +132,17 @@ UTP.prototype._closeMaybe = function () { | |
if (this._closing && !this.connections.length && !this._sending.length && this._inited && !this._closed) { | ||
this._closed = true | ||
binding.utp_napi_close(this._handle) | ||
} else { | ||
for (const conn of this.connections) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't understand how these lines could be missing: When you close the server, any open connections are supposed to be closed, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, each connection must be closed individually There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Same as tcp) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The instances created in the tests are not properly torn down then, causing a lot of weird errors happen when I tried to remove this. Checking the tests for "why they fail because this is removed" is the reason this takes to long for me to continue. |
||
conn.destroy(new Error('server closed')) | ||
} | ||
} | ||
} | ||
|
||
UTP.prototype.connect = function (port, ip) { | ||
if (!this._inited) this.bind() | ||
if (!ip) ip = '127.0.0.1' | ||
const conn = new Connection(this, port, ip, null, this._allowHalfOpen) | ||
if (!isIP(ip)) conn._resolveAndConnect(port, ip) | ||
else conn._connect(port, ip || '127.0.0.1') | ||
return conn | ||
return new Connection(this, port, ip, null, this._allowHalfOpen) | ||
} | ||
|
||
UTP.prototype.listen = function (port, ip, onlistening) { | ||
|
@@ -204,11 +205,13 @@ UTP.prototype._onmessage = function (size, port, address) { | |
this.emit('message', message, { address, family: 'IPv4', port }) | ||
|
||
if (this._buffer.length - this._offset <= 65536) { | ||
// max package buffer is 64kb and we wanna make sure we have room for that | ||
// returning the buffer indicates to the native code that | ||
// the buffer has changed | ||
this._buffer = Buffer.allocUnsafe(this._buffer.length) | ||
this._offset = 0 | ||
return this._buffer | ||
} | ||
|
||
return EMPTY | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This handle is now closed serially. If I leave his in parallel, it causes a segfault. Probably a timing error, but I couldn't figure out its cause.