projects
/
jSite2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
SSKKeypair reply message
[jSite2.git]
/
src
/
net
/
pterodactylus
/
util
/
fcp
/
FcpConnectionHandler.java
diff --git
a/src/net/pterodactylus/util/fcp/FcpConnectionHandler.java
b/src/net/pterodactylus/util/fcp/FcpConnectionHandler.java
index
2693c1f
..
cbea0e2
100644
(file)
--- a/
src/net/pterodactylus/util/fcp/FcpConnectionHandler.java
+++ b/
src/net/pterodactylus/util/fcp/FcpConnectionHandler.java
@@
-25,26
+25,50
@@
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
/**
import java.nio.charset.Charset;
/**
- *
TODO
+ *
Handles an FCP connection to a node.
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
* @version $Id$
*/
public class FcpConnectionHandler implements Runnable {
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
* @version $Id$
*/
public class FcpConnectionHandler implements Runnable {
+ /** The underlying connection. */
private final FcpConnection fcpConnection;
private final FcpConnection fcpConnection;
+
+ /** The input stream from the node. */
private final InputStream remoteInputStream;
private final InputStream remoteInputStream;
-
+
+ /** Whether to stop the connection handler. */
+ private boolean shouldStop;
+
+ /** Whether the next read line feed should be ignored. */
private boolean ignoreNextLinefeed;
private boolean ignoreNextLinefeed;
+ /**
+ * Creates a new connection handler that operates on the given connection
+ * and input stream.
+ *
+ * @param fcpConnection
+ * The underlying FCP connection
+ * @param remoteInputStream
+ * The input stream from the node
+ */
public FcpConnectionHandler(FcpConnection fcpConnection, InputStream remoteInputStream) {
this.fcpConnection = fcpConnection;
this.remoteInputStream = remoteInputStream;
}
public FcpConnectionHandler(FcpConnection fcpConnection, InputStream remoteInputStream) {
this.fcpConnection = fcpConnection;
this.remoteInputStream = remoteInputStream;
}
+ /**
+ * {@inheritDoc}
+ */
public void run() {
FcpMessage fcpMessage = null;
while (true) {
public void run() {
FcpMessage fcpMessage = null;
while (true) {
+ synchronized (this) {
+ if (shouldStop) {
+ break;
+ }
+ }
try {
String line = readLine();
System.out.println("read line: " + line);
try {
String line = readLine();
System.out.println("read line: " + line);
@@
-72,11
+96,25
@@
public class FcpConnectionHandler implements Runnable {
String value = line.substring(equalSign + 1);
fcpMessage.setField(field, value);
} catch (IOException e) {
String value = line.substring(equalSign + 1);
fcpMessage.setField(field, value);
} catch (IOException e) {
+ break;
}
}
}
/**
}
}
}
/**
+ * Stops the connection handler.
+ */
+ public void stop() {
+ synchronized (this) {
+ shouldStop = true;
+ }
+ }
+
+ //
+ // PRIVATE METHODS
+ //
+
+ /**
* Reads bytes from {@link #remoteInputStream} until ‘\r’ or ‘\n’ are
* encountered and decodes the read bytes using UTF-8.
*
* Reads bytes from {@link #remoteInputStream} until ‘\r’ or ‘\n’ are
* encountered and decodes the read bytes using UTF-8.
*