File tree Expand file tree Collapse file tree 1 file changed +19
-11
lines changed Expand file tree Collapse file tree 1 file changed +19
-11
lines changed Original file line number Diff line number Diff line change @@ -259,25 +259,33 @@ function Connection(args) {
259
259
}
260
260
261
261
var queue = [ ] ;
262
+
263
+ function mergeFirstBuffersAndCheckInput ( ) {
264
+ if ( queue . length > 1 ) {
265
+ // Merge the first two buffers
266
+ var first = queue . shift ( ) ;
267
+ var b = new Buffer ( first . length + queue [ 0 ] . length ) ;
268
+ first . copy ( b ) ;
269
+ queue [ 0 ] . copy ( b , first . length ) ;
270
+ queue [ 0 ] = b ;
271
+ return checkInput ( ) ;
272
+ } else {
273
+ return ;
274
+ }
275
+ }
276
+
262
277
function checkInput ( ) {
263
278
if ( queue . length === 0 ) { return ; }
264
279
var first = queue [ 0 ] ;
280
+ if ( first . length < 5 ) {
281
+ return mergeFirstBuffersAndCheckInput ( ) ;
282
+ }
265
283
var code = String . fromCharCode ( first [ 0 ] ) ;
266
284
var length = first . int32Read ( 1 ) - 4 ;
267
285
268
286
// Make sure we have a whole message, TCP comes in chunks
269
287
if ( first . length < length + 5 ) {
270
- if ( queue . length > 1 ) {
271
- // Merge the first two buffers
272
- queue . shift ( ) ;
273
- var b = new Buffer ( first . length + queue [ 0 ] . length ) ;
274
- first . copy ( b ) ;
275
- queue [ 0 ] . copy ( b , first . length ) ;
276
- queue [ 0 ] = b ;
277
- return checkInput ( ) ;
278
- } else {
279
- return ;
280
- }
288
+ return mergeFirstBuffersAndCheckInput ( ) ;
281
289
}
282
290
var message = first . slice ( 5 , 5 + length ) ;
283
291
if ( first . length === 5 + length ) {
You can’t perform that action at this time.
0 commit comments