[Webfunds-commits] java/webfunds/sox HttpAgent.java
Ian Grigg
iang@cypherpunks.ai
Mon, 26 Feb 2001 21:25:45 -0400 (AST)
iang 01/02/26 21:25:44
Modified: webfunds/sox HttpAgent.java
Log:
better handling of dropped connections, under some conditions
there are different responses from Java it seems...
Revision Changes Path
1.21 +19 -7 java/webfunds/sox/HttpAgent.java
Index: HttpAgent.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/HttpAgent.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- HttpAgent.java 2000/08/31 14:17:14 1.20
+++ HttpAgent.java 2001/02/27 01:25:44 1.21
@@ -1,5 +1,5 @@
/*
- * $Id: HttpAgent.java,v 1.20 2000/08/31 14:17:14 iang Exp $
+ * $Id: HttpAgent.java,v 1.21 2001/02/27 01:25:44 iang Exp $
*
* Copyright (c) Systemics Ltd 1995-1999 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -197,8 +197,12 @@
{
int ch = is.read();
if (ch < 0)
+ {
+ if (i == 0) // EOF
+ return null;
throw new IOException("EOF after " + i + ":" +
- " <<" + new String(buf) + ">>");
+ " <<" + new String(buf, 0, i) + ">>");
+ }
buf[i] = (byte)ch;
if (i > 0 && buf[i] == '\n' && buf[i-1] == '\r') // CRNL
return new String(buf, 0, i - 1); // no term
@@ -248,16 +252,25 @@
//
while (true)
{
- String line;
+ String s;
try {
- line = getLine(is).trim();
+ s = getLine(is);
} catch (IOException ex) {
logmsg(ex.getMessage());
throw new SOXAgentReplyException(errno, "headers: " + ex);
}
+ if (s == null) // sometimes returns closed as EOF
+ {
+ ok = false;
+ errno = SOXException.LATER_DOWN;
+ errors += " later, down: <<EOF>>";
+ break;
+ }
+
+ String line = s.trim();
- if ("".equals(line))
- break ; // next is message body
+ if ("".equals(line)) // this is empty line, waiting for
+ break ; // next is message body
if (line.startsWith(serverVersion))
{
@@ -283,7 +296,6 @@
try {
length = new Integer(lenString).intValue();
} catch (NumberFormatException ex) {
- ex = null; // jikes
ok = false;
errors += " bad len: <<" + line + ">>";
logmsg(errors);