-
Notifications
You must be signed in to change notification settings - Fork 283
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
apply PayloadSender fix from #1886 and add unit test #1887
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 |
---|---|---|
|
@@ -70,16 +70,26 @@ export class PayloadSender { | |
|
||
private writePacket(packet: ISendPacket): void { | ||
try { | ||
let sendHeaderBuffer: Buffer = Buffer.alloc(PayloadConstants.MaxHeaderLength); | ||
HeaderSerializer.serialize(packet.header, sendHeaderBuffer); | ||
this.sender.send(sendHeaderBuffer); | ||
|
||
if (packet.header.payloadLength > 0 && packet.payload) { | ||
let count = packet.header.payloadLength; | ||
while (count > 0) { | ||
|
||
let leftOver = packet.header.payloadLength; | ||
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. Maybe rename to remainingBytes |
||
|
||
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. blank line |
||
while (leftOver > 0) { | ||
let count = leftOver <= PayloadConstants.MaxPayloadLength ? leftOver : PayloadConstants.MaxPayloadLength; | ||
let chunk = packet.payload.read(count); | ||
|
||
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. blank line |
||
var header = packet.header; | ||
header.payloadLength = count; | ||
header.end = leftOver <= PayloadConstants.MaxPayloadLength; | ||
|
||
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. blank line |
||
let sendHeaderBuffer: Buffer = Buffer.alloc(PayloadConstants.MaxHeaderLength); | ||
|
||
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. blank line |
||
HeaderSerializer.serialize(header, sendHeaderBuffer); | ||
|
||
this.sender.send(sendHeaderBuffer); | ||
|
||
this.sender.send(chunk); | ||
count -= chunk.length; | ||
leftOver-= chunk.length; | ||
} | ||
|
||
if (packet.sentCallback) { | ||
|
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.
blank line