Repository navigation
stream_base: expose bytesRead getter
#6284
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,6 +111,10 @@ function initSocketHandle(self) { | |
| } | ||
| } | ||
|
|
||
|
|
||
| const BYTES_READ = Symbol('bytesRead'); | ||
|
|
||
|
|
||
| function Socket(options) { | ||
| if (!(this instanceof Socket)) return new Socket(options); | ||
|
|
||
|
|
@@ -180,7 +184,7 @@ function Socket(options) { | |
| this._server = null; | ||
|
|
||
| // Used after `.destroy()` | ||
| this._bytesRead = 0; | ||
| this[BYTES_READ] = 0; | ||
| } | ||
| util.inherits(Socket, stream.Duplex); | ||
|
|
||
|
|
@@ -473,7 +477,7 @@ Socket.prototype._destroy = function(exception, cb) { | |
| debug('close handle'); | ||
| var isException = exception ? true : false; | ||
| // `bytesRead` should be accessible after `.destroy()` | ||
| this._bytesRead = this._handle.bytesRead; | ||
| this[BYTES_READ] = this._handle.bytesRead; | ||
|
|
||
| this._handle.close(() => { | ||
| debug('emit close'); | ||
|
|
@@ -582,7 +586,7 @@ Socket.prototype._getpeername = function() { | |
| }; | ||
|
|
||
| Socket.prototype.__defineGetter__('bytesRead', function() { | ||
|
Member
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. Since e.g.
Member
Author
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. Ack. |
||
| return this._handle ? this._handle.bytesRead : this._bytesRead; | ||
| return this._handle ? this._handle.bytesRead : this[BYTES_READ]; | ||
| }); | ||
|
|
||
| Socket.prototype.__defineGetter__('remoteAddress', function() { | ||
|
|
||
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.
I think the naming preference is something like
kBytesReadThere 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.
Is it?
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.
Ok, yep, I've seen comments both ways but the code doesn't lie ;-)