From 068d3b1dbd4ec3346d2884d0029db95698821d06 Mon Sep 17 00:00:00 2001
From: akwizgran <michael@briarproject.org>
Date: Fri, 7 Dec 2012 16:20:53 +0000
Subject: [PATCH] The reliability layer should run when the modem is off the
 hook.

---
 .../src/net/sf/briar/plugins/modem/ModemImpl.java    | 12 ++++--------
 1 file changed, 4 insertions(+), 8 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 45ca855b2e..b61aacd97c 100644
--- a/briar-core/src/net/sf/briar/plugins/modem/ModemImpl.java
+++ b/briar-core/src/net/sf/briar/plugins/modem/ModemImpl.java
@@ -49,7 +49,6 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 		connected = new AtomicBoolean(false);
 		line = new byte[MAX_LINE_LENGTH];
 		reliabilityLayer = new ReliabilityLayer(this);
-		reliabilityLayer.start();
 	}
 
 	public void start() throws IOException {
@@ -92,12 +91,8 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 	}
 
 	public void stop() throws IOException {
-		if(offHook.tryAcquire()) {
-			reliabilityLayer.stop();
-			offHook.release();
-		} else {
-			hangUp();
-		}
+		if(offHook.tryAcquire()) offHook.release();
+		else hangUp();
 		try {
 			port.closePort();
 		} catch(SerialPortException e) {
@@ -111,6 +106,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 				LOG.info("Not dialling - call in progress");
 			return false;
 		}
+		reliabilityLayer.start();
 		if(LOG.isLoggable(INFO)) LOG.info("Dialling");
 		try {
 			port.writeBytes(("ATDT" + number + "\r\n").getBytes("US-ASCII"));
@@ -150,7 +146,6 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 		}
 		reliabilityLayer.stop();
 		reliabilityLayer = new ReliabilityLayer(this);
-		reliabilityLayer.start();
 		connected.set(false);
 		offHook.release();
 	}
@@ -244,6 +239,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
 				LOG.info("Not answering - call in progress");
 			return;
 		}
+		reliabilityLayer.start();
 		if(LOG.isLoggable(INFO)) LOG.info("Answering");
 		try {
 			port.writeBytes("ATA\r\n".getBytes("US-ASCII"));
-- 
GitLab