Add Maven project description.
[jFCPlib.git] / src / net / pterodactylus / fcp / FcpConnectionHandler.java
index b6404c5..dbf0969 100644 (file)
@@ -1,6 +1,5 @@
 /*
- * jSite2 - FcpConnectionHandler.java -
- * Copyright © 2008 David Roden
+ * jFCPlib - FcpConnectionHandler.java - Copyright © 2008 David Roden
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -26,9 +25,8 @@ import java.nio.charset.Charset;
 
 /**
  * Handles an FCP connection to a node.
- * 
+ *
  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
- * @version $Id$
  */
 class FcpConnectionHandler implements Runnable {
 
@@ -47,7 +45,7 @@ class FcpConnectionHandler implements Runnable {
        /**
         * Creates a new connection handler that operates on the given connection
         * and input stream.
-        * 
+        *
         * @param fcpConnection
         *            The underlying FCP connection
         * @param remoteInputStream
@@ -63,6 +61,7 @@ class FcpConnectionHandler implements Runnable {
         */
        public void run() {
                FcpMessage fcpMessage = null;
+               Throwable throwable = null;
                while (true) {
                        synchronized (this) {
                                if (shouldStop) {
@@ -83,7 +82,7 @@ class FcpConnectionHandler implements Runnable {
                                        fcpMessage = new FcpMessage(line);
                                        continue;
                                }
-                               if ("EndMessage".equals(line)) {
+                               if ("EndMessage".equalsIgnoreCase(line) || "Data".equalsIgnoreCase(line)) {
                                        fcpConnection.handleMessage(fcpMessage);
                                        fcpMessage = null;
                                }
@@ -96,11 +95,12 @@ class FcpConnectionHandler implements Runnable {
                                String value = line.substring(equalSign + 1);
                                assert fcpMessage != null: "fcp message is null";
                                fcpMessage.setField(field, value);
-                       } catch (IOException e) {
+                       } catch (IOException ioe1) {
+                               throwable = ioe1;
                                break;
                        }
                }
-               fcpConnection.handleDisconnect();
+               fcpConnection.handleDisconnect(throwable);
        }
 
        /**
@@ -119,7 +119,7 @@ class FcpConnectionHandler implements Runnable {
        /**
         * Reads bytes from {@link #remoteInputStream} until ‘\r’ or ‘\n’ are
         * encountered and decodes the read bytes using UTF-8.
-        * 
+        *
         * @return The decoded line
         * @throws IOException
         *             if an I/O error occurs