From 5516503f67053514b2fb3460706a66f79b166964 Mon Sep 17 00:00:00 2001 From: akwizgran <michael@briarproject.org> Date: Thu, 6 Dec 2012 16:56:08 +0000 Subject: [PATCH] Removed broken code for flushing the output stream. --- .../net/sf/briar/plugins/modem/ModemImpl.java | 17 +---------------- .../briar/plugins/modem/ReliabilityLayer.java | 6 +----- .../src/net/sf/briar/plugins/modem/Sender.java | 4 ---- .../briar/plugins/modem/SenderOutputStream.java | 7 +------ .../net/sf/briar/plugins/modem/SlipEncoder.java | 4 ---- .../sf/briar/plugins/modem/WriteHandler.java | 2 -- 6 files changed, 3 insertions(+), 37 deletions(-) diff --git a/briar-core/src/net/sf/briar/plugins/modem/ModemImpl.java b/briar-core/src/net/sf/briar/plugins/modem/ModemImpl.java index bde47d9eaf..f389b7dfa2 100644 --- a/briar-core/src/net/sf/briar/plugins/modem/ModemImpl.java +++ b/briar-core/src/net/sf/briar/plugins/modem/ModemImpl.java @@ -33,7 +33,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener { private final Callback callback; private final SerialPort port; private final AtomicBoolean initialised, connected; - private final Semaphore offHook, writing; + private final Semaphore offHook; private final byte[] line; private int lineLen = 0; @@ -46,7 +46,6 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener { port = new SerialPort(portName); initialised = new AtomicBoolean(false); offHook = new Semaphore(1); - writing = new Semaphore(1); connected = new AtomicBoolean(false); line = new byte[MAX_LINE_LENGTH]; reliabilityLayer = new ReliabilityLayer(this); @@ -152,28 +151,14 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener { } public void handleWrite(byte[] b) throws IOException { - try { - writing.acquire(); - } catch(InterruptedException e) { - tryToClose(port); - Thread.currentThread().interrupt(); - throw new IOException("Interrupted while waiting to write"); - } try { port.writeBytes(b); } catch(SerialPortException e) { tryToClose(port); throw new IOException(e.toString()); - } finally { - writing.release(); } } - public void waitForWritesToComplete() throws InterruptedException { - writing.acquire(); - writing.release(); - } - public void serialEvent(SerialPortEvent ev) { try { if(ev.isRXCHAR()) { diff --git a/briar-core/src/net/sf/briar/plugins/modem/ReliabilityLayer.java b/briar-core/src/net/sf/briar/plugins/modem/ReliabilityLayer.java index 197709ec9d..e61748ab90 100644 --- a/briar-core/src/net/sf/briar/plugins/modem/ReliabilityLayer.java +++ b/briar-core/src/net/sf/briar/plugins/modem/ReliabilityLayer.java @@ -27,6 +27,7 @@ class ReliabilityLayer implements ReadHandler, WriteHandler { ReliabilityLayer(WriteHandler writeHandler) { this.writeHandler = writeHandler; + // FIXME: Don't let references to this escape the constructor SlipEncoder encoder = new SlipEncoder(this); Sender sender = new Sender(encoder); receiver = new Receiver(sender); @@ -90,9 +91,4 @@ class ReliabilityLayer implements ReadHandler, WriteHandler { if(LOG.isLoggable(INFO)) LOG.info("Queueing " + b.length + " bytes"); if(b.length > 0) writes.add(b); } - - public void waitForWritesToComplete() throws InterruptedException { - if(writer != null) writer.join(); - writeHandler.waitForWritesToComplete(); - } } diff --git a/briar-core/src/net/sf/briar/plugins/modem/Sender.java b/briar-core/src/net/sf/briar/plugins/modem/Sender.java index 3217482ad6..9c8ef82af4 100644 --- a/briar-core/src/net/sf/briar/plugins/modem/Sender.java +++ b/briar-core/src/net/sf/briar/plugins/modem/Sender.java @@ -204,10 +204,6 @@ class Sender { writeHandler.handleWrite(d.getBuffer()); } - void waitForWritesToComplete() throws InterruptedException { - writeHandler.waitForWritesToComplete(); - } - private static class Outstanding { private final Data data; diff --git a/briar-core/src/net/sf/briar/plugins/modem/SenderOutputStream.java b/briar-core/src/net/sf/briar/plugins/modem/SenderOutputStream.java index 531fa0417c..e2da6bd1ac 100644 --- a/briar-core/src/net/sf/briar/plugins/modem/SenderOutputStream.java +++ b/briar-core/src/net/sf/briar/plugins/modem/SenderOutputStream.java @@ -23,12 +23,7 @@ class SenderOutputStream extends OutputStream { @Override public void flush() throws IOException { if(offset > Data.HEADER_LENGTH) send(false); - try { - sender.waitForWritesToComplete(); - } catch(InterruptedException e) { - Thread.currentThread().interrupt(); - throw new IOException("Interrupted while flushing output stream"); - } + // FIXME: Wait for asynchronous writes to complete } @Override diff --git a/briar-core/src/net/sf/briar/plugins/modem/SlipEncoder.java b/briar-core/src/net/sf/briar/plugins/modem/SlipEncoder.java index e106d66dec..0fc327a43f 100644 --- a/briar-core/src/net/sf/briar/plugins/modem/SlipEncoder.java +++ b/briar-core/src/net/sf/briar/plugins/modem/SlipEncoder.java @@ -35,8 +35,4 @@ class SlipEncoder implements WriteHandler { encoded[encodedLength - 1] = END; writeHandler.handleWrite(encoded); } - - public void waitForWritesToComplete() throws InterruptedException { - writeHandler.waitForWritesToComplete(); - } } diff --git a/briar-core/src/net/sf/briar/plugins/modem/WriteHandler.java b/briar-core/src/net/sf/briar/plugins/modem/WriteHandler.java index f4780ffac1..fdf4d2c153 100644 --- a/briar-core/src/net/sf/briar/plugins/modem/WriteHandler.java +++ b/briar-core/src/net/sf/briar/plugins/modem/WriteHandler.java @@ -5,6 +5,4 @@ import java.io.IOException; interface WriteHandler { void handleWrite(byte[] b) throws IOException; - - void waitForWritesToComplete() throws InterruptedException; } -- GitLab