@@ -16,10 +16,8 @@ var states = {
1616 CONNECTING : 0 ,
1717 CONNECTED : 1 ,
1818 AWAITING : 2 ,
19- DESTROYED : 5 ,
20- DISONECTED : 6 ,
21- PREHELLO : 7 ,
22- AWAITING_LENGTH : 8
19+ INITED : 3 ,
20+ PREHELLO : 4
2321} ;
2422
2523var requestMethods = [ 'select' , 'delete' , 'insert' , 'replace' , 'update' , 'eval' , 'call' ] ;
@@ -47,7 +45,6 @@ function TarantoolConnection (options){
4745 writable : true
4846 } ) ;
4947 this . state = states . INITED ;
50- this . emitter = new EventEmitter ( ) ;
5148 this . options = _ . extend ( defaultOptions , options ) ;
5249 this . commandsQueue = [ ] ;
5350 this . awaitingDestroy = false ;
@@ -171,7 +168,7 @@ TarantoolConnection.prototype.onError = function(error){
171168 this . commandsQueue = [ ] ;
172169} ;
173170
174- TarantoolConnection . prototype . _interupt = function ( ) {
171+ TarantoolConnection . prototype . _interupt = function ( error ) {
175172 for ( var i = 0 ; i < this . commandsQueue . length ; i ++ ) {
176173 var dfd = this . commandsQueue [ i ] [ 0 ] == tarantoolConstants . RequestCode . rqConnect ? this . commandsQueue [ i ] [ 1 ]
177174 : this . commandsQueue [ i ] [ 2 ] ;
@@ -181,9 +178,15 @@ TarantoolConnection.prototype._interupt = function(){
181178
182179TarantoolConnection . prototype . connect = function ( ) {
183180 var dfd = vow . defer ( ) ;
184- this . state = states . CONNECTING ;
185- this . commandsQueue . push ( [ tarantoolConstants . RequestCode . rqConnect , dfd ] ) ;
186- this . socket . connect ( { port : this . options . port , host : this . options . host } ) ;
181+ if ( this . state == states . INITED )
182+ {
183+ this . state = states . CONNECTING ;
184+ this . commandsQueue . push ( [ tarantoolConstants . RequestCode . rqConnect , dfd ] ) ;
185+ this . socket . connect ( { port : this . options . port , host : this . options . host } ) ;
186+
187+ }
188+ else
189+ dfd . reject ( this . awaitingDestroy ? 'already destroyed' : 'already connected' ) ;
187190 return dfd . promise ( ) ;
188191} ;
189192
@@ -201,6 +204,9 @@ TarantoolConnection.prototype.select = function(spaceId, indexId, limit, offset,
201204 var dfd = vow . defer ( ) ;
202205 var reqId = requestId . getId ( ) ;
203206 var header = this . _header ( tarantoolConstants . RequestCode . rqSelect , reqId ) ;
207+ //don't need a key for all iterator
208+ if ( iterator == 'all' )
209+ key = [ ] ;
204210 var buffered = {
205211 spaceId : msgpack . pack ( spaceId ) ,
206212 indexId : msgpack . pack ( indexId ) ,
@@ -221,7 +227,7 @@ TarantoolConnection.prototype.select = function(spaceId, indexId, limit, offset,
221227 return dfd . promise ( ) ;
222228} ;
223229
224- TarantoolConnection . prototype . delete = function ( spaceId , indexId , key , limit ) {
230+ TarantoolConnection . prototype . delete = function ( spaceId , indexId , key ) {
225231 var dfd = vow . defer ( ) ;
226232 var reqId = requestId . getId ( ) ;
227233 var header = this . _header ( tarantoolConstants . RequestCode . rqDelete , reqId ) ;
@@ -363,7 +369,8 @@ TarantoolConnection.prototype.destroy = function(interupt){
363369 var dfd = vow . defer ( ) ;
364370 if ( interupt )
365371 {
366- this . _interupt ( ) ;
372+ this . _interupt ( 'force destroy socket' ) ;
373+ this . socket . destroy ( ) ;
367374 dfd . resolve ( true ) ;
368375 }
369376 else
0 commit comments