@@ -58,11 +58,10 @@ export class R2PipeSpawn extends R2PipeBase {
5858}
5959
6060function pipeCmdOutput ( r2 , proc , data ) {
61- r2 . running = true ;
6261 let len = data . length ;
6362
6463 if ( r2 . pipeQueue . length < 1 ) {
65- return new Error ( 'r2pipe error: No pending commands for incomming data' ) ;
64+ return new Error ( 'r2pipe error: No pending commands for incoming data' ) ;
6665 }
6766
6867 if ( data . length > 1 && data [ 0 ] === 0x00 ) {
@@ -71,8 +70,7 @@ function pipeCmdOutput(r2, proc, data) {
7170 if ( data [ len - 1 ] !== 0x00 ) {
7271 r2 . pipeQueue [ 0 ] . result += data . toString ( ) ;
7372 data = "" ;
74- // return;
75- /// return r2.pipeQueue[0].result;
73+ return ;
7674 }
7775
7876 while ( data [ len - 1 ] == 0x00 ) {
@@ -93,8 +91,9 @@ function pipeCmdOutput(r2, proc, data) {
9391 } catch ( e ) {
9492 r2 . pipeQueue [ 0 ] . cb ( e , null ) ;
9593 }
94+ } else {
95+ r2 . running = false ;
9696 }
97- r2 . running = false ;
9897}
9998
10099function r2bind ( child , cb , r2cmd ) {
@@ -118,14 +117,14 @@ function r2bind(child, cb, r2cmd) {
118117 } ,
119118 /* Run cmd and return plaintext output */
120119 cmd : ( command , commandCallback ) => {
121- // s = util.cleanCmd(s);
122120 r2 . pipeQueue . push ( {
123121 cmd : command ,
124122 cb : commandCallback ,
125123 result : '' ,
126124 error : null
127125 } ) ;
128- if ( r2 . pipeQueue . length === 1 ) {
126+ if ( ! r2 . running && r2 . pipeQueue . length === 1 ) {
127+ r2 . running = true ;
129128 child . stdin . write ( command + '\n' ) ;
130129 }
131130 } ,
@@ -142,48 +141,10 @@ function r2bind(child, cb, r2cmd) {
142141 }
143142 } ;
144143
145- /* handle SDTERR message */
146- if ( child . stderr !== null ) {
147- child . stderr . on ( 'data' , function ( data ) {
148- /* Set as running for connect & launch methods */
149- if ( typeof errmsg === 'string' ) {
150- errmsg += data . toString ( ) ;
151- if ( errmsg . length > 1024 * 32 ) {
152- errmsg = null ;
153- }
154- }
155- if ( ! r2 . running && ( typeof r2cmd !== 'string' ) ) {
156- r2 . running = true ;
157- if ( typeof cb === 'function' ) {
158- cb ( null , r2 ) ;
159- } else {
160- throw new Error ( 'Callback in .cmd() is not a function' ) ;
161- }
162- }
163- } ) ;
164- }
165-
166- /* handle STDOUT nessages */
144+ /* handle STDOUT messages */
167145 if ( child . stdout !== null ) {
168146 child . stdout . on ( 'data' , data => {
169- if ( r2 . running ) {
170- console . error ( "race" ) ;
171- }
172147 pipeCmdOutput ( r2 , child , data ) ;
173- /*
174- // console.log("received data: " + data);
175- // Set as running for pipe method
176- if (running) {
177- console.log("RUNING");
178- if (typeof r2cmd === 'string') {
179- pipeCmdOutput.bind(r2)(child, data, cb);
180- }
181- } else {
182- console.log("not RUNING");
183- running = true;
184- cb(null, r2);
185- }
186- */
187148 } ) ;
188149 } else {
189150 cb ( null , r2 ) ; // Callback for connect
0 commit comments