-/* $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
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;
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);