@@ -20,11 +20,6 @@ module.exports = class Connection extends EventEmitter {
2020 // When an IRC connection was successfully registered.
2121 this . registered = false ;
2222
23- this . read_buffer = [ ] ;
24- this . reading_buffer = false ;
25-
26- this . read_command_buffer = [ ] ;
27-
2823 this . transport = null ;
2924
3025 this . _timers = [ ] ;
@@ -94,8 +89,7 @@ module.exports = class Connection extends EventEmitter {
9489 }
9590
9691 function socketLine ( line ) {
97- that . read_buffer . push ( line ) ;
98- that . processReadBuffer ( ) ;
92+ that . addReadBuffer ( line ) ;
9993 }
10094
10195 function socketClose ( err ) {
@@ -158,8 +152,10 @@ module.exports = class Connection extends EventEmitter {
158152 }
159153
160154 addReadBuffer ( line ) {
161- this . read_buffer . push ( line ) ;
162- this . processReadBuffer ( ) ;
155+ const message = ircLineParser ( line ) ;
156+
157+ this . emit ( 'raw' , { line : line , from_server : true } ) ;
158+ this . emit ( 'message' , message , line ) ;
163159 }
164160
165161 write ( data , callback ) {
@@ -246,52 +242,4 @@ module.exports = class Connection extends EventEmitter {
246242 return this . transport . setEncoding ( encoding ) ;
247243 }
248244 }
249-
250- /**
251- * Process the buffered messages recieved from the IRCd
252- * Will only process 4 lines per JS tick so that node can handle any other events while
253- * handling a large buffer
254- */
255- processReadBuffer ( continue_processing ) {
256- // If we already have the read buffer being iterated through, don't start
257- // another one.
258- if ( this . reading_buffer && ! continue_processing ) {
259- return ;
260- }
261-
262- const that = this ;
263- const lines_per_js_tick = 40 ;
264- let processed_lines = 0 ;
265- let line ;
266- let message ;
267-
268- this . reading_buffer = true ;
269-
270- while ( processed_lines < lines_per_js_tick && this . read_buffer . length > 0 ) {
271- line = this . read_buffer . shift ( ) ;
272- if ( ! line ) {
273- continue ;
274- }
275-
276- message = ircLineParser ( line ) ;
277-
278- if ( ! message ) {
279- // A malformed IRC line
280- continue ;
281- }
282- this . emit ( 'raw' , { line : line , from_server : true } ) ;
283- this . emit ( 'message' , message , line ) ;
284-
285- processed_lines ++ ;
286- }
287-
288- // If we still have items left in our buffer then continue reading them in a few ticks
289- if ( this . read_buffer . length > 0 ) {
290- this . setTimeout ( function ( ) {
291- that . processReadBuffer ( true ) ;
292- } , 1 ) ;
293- } else {
294- this . reading_buffer = false ;
295- }
296- }
297245} ;
0 commit comments