File tree Expand file tree Collapse file tree 1 file changed +13
-8
lines changed
Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Original file line number Diff line number Diff line change 22 'use strict' ;
33
44 var path = require ( 'path' ) ,
5- findit = require ( 'findit' ) ,
65
7- assert = require ( 'assert ' ) ,
6+ findit = require ( 'findit ' ) ,
87 io = require ( 'socket.io' ) ,
98
109 Socket ,
3534
3635 function onConnection ( socket , onMsg , callback ) {
3736 var msg , onDisconnect , onMessage ,
38- onFind = function ( conNum , data ) {
37+ indexEmpty = Clients . indexOf ( null ) ,
38+ onFind = function ( conNum , data ) {
3939 var dir , name ,
4040 d = data ;
4141
5555 onMsg = null ;
5656 }
5757
58- assert ( socket , 'socket could not be empty!' ) ;
59- assert ( callback , 'callback could not be empty!' ) ;
60-
61- ++ ConNum ;
58+ if ( indexEmpty >= 0 )
59+ ConNum = indexEmpty ;
60+ else
61+ ConNum = Clients . length ;
6262
6363 if ( ! Clients [ ConNum ] ) {
6464 msg = log ( ConNum , 'find connected' ) ;
7373 onFind ( conNum , command ) ;
7474 } . bind ( null , ConNum ) ,
7575 onDisconnect = function ( conNum ) {
76- Clients [ conNum ] = null ;
76+ if ( Clients . length !== conNum + 1 ) {
77+ Clients [ conNum ] = null ;
78+ } else {
79+ Clients . pop ( ) ;
80+ -- ConNum ;
81+ }
7782
7883 log ( conNum , 'find disconnected' ) ;
7984
You can’t perform that action at this time.
0 commit comments