From ad53865723f88bdd76ff0005ac48cf0285bcef23 Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Fri, 5 Aug 2005 22:44:15 +0000
Subject: [PATCH] Use socket_select() to allow waiting on bith the IRC socket
 and the client socket instead of the broken sleep(1) on input previously
 used.

This allows irc.js to run with MUCH lower CPU utilization.
---
 exec/irc.js | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/exec/irc.js b/exec/irc.js
index 063ade99cb..66a4b3f545 100644
--- a/exec/irc.js
+++ b/exec/irc.js
@@ -111,6 +111,9 @@ while(!connected)  {
 }
 
 // Main loop
+socks = new Array;
+socks.push(sock);
+socks.push(client.socket);
 while(!quit)  {
 	if(!sock.is_connected || !connected)  {
 		alert("Lost connection");
@@ -126,8 +129,15 @@ while(!quit)  {
 		clean_exit();
 	}
 
-	screen.update();
-	recieve_command();
+	ready=socket_select(socks, 1);
+	for(thissock in ready) {
+		if(ready[thissock]==0) {	// IRC server
+			recieve_command();
+		}
+		if(ready[thissock]==1) {	// Client
+			screen.update();
+		}
+	}
 }
 sock.close();
 clean_exit();
@@ -1242,12 +1252,12 @@ function Screen_update_input_line()  {
 }
 
 function Screen_update()  {
-	var key=console.inkey();
-	if(key!="")  {
-		this.handle_key(key);
-	}
-	else {
-		sleep(1);
+	while(1) {
+		var key=console.inkey();
+		if(key!="")
+			this.handle_key(key);
+		else
+			break;
 	}
 }
 
-- 
GitLab