*** empty log message ***
authorMatthew Mondor <mmondor@pulsar-zone.net>
Tue, 22 Aug 2006 11:43:59 +0000 (11:43 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Tue, 22 Aug 2006 11:43:59 +0000 (11:43 +0000)
mmsoftware/js/jslib/fd.js

index a7b76ac..bbaf9bf 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: fd.js,v 1.7 2006/08/12 13:18:50 mmondor Exp $ */
+/* $Id: fd.js,v 1.8 2006/08/22 11:43:59 mmondor Exp $ */
 
 /*
  * Copyright (C) 2006, Matthew Mondor
@@ -114,14 +114,15 @@ FD.prototype.bread = function(max, poll)
                        data = '';
                        this.berror = this.BERROR;
                }
-               this.bread_buffer += data;
-               if (data.length == 0) {
+               if (data.length != 0)
+                       this.bread_buffer += data;
+               else {
                        if (!poll) {
                                this.berror = this.BEAGAIN;
                                return data;
                        }
                        try {
-                               this.events = FD.POLLIN | FD.POLLHUP;
+                               this.events = FD.POLLIN;
                                e = FD.poll([this], this.input_timeout);
                                if (e.length == 0) {
                                        this.berror = this.BTIMEOUT;
@@ -277,6 +278,20 @@ FD.prototype.breadline = function(max, poll)
                        this.bunread(data.substr(idx + 2));
                        return data.substr(0, idx);
                }
+               /*
+                * XXX For some reason this doesn't work with stdin, only
+                * SOCK_STREAM sockets descriptors.  Needed in case we are not
+                * polling because although bread() would return null with
+                * BEAGAIN in case it doesn't poll and no data remains in the
+                * buffer to provide, if there is buffered data but no new
+                * data to read, we could loop endlessly taking a lot of CPU
+                * time until an EOL is really detected.
+                */
+               if (!poll) {
+                       this.bunread(data2);
+                       this.berror = this.BEAGAIN;
+                       return null;
+               }
        }
 
        this.bunread(data);