mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 06:09:55 +01:00
Use +++ATH to hang up modem instead of lowering DTR (untested).
This commit is contained in:
@@ -31,6 +31,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
};
|
};
|
||||||
private static final int OK_TIMEOUT = 5 * 1000; // Milliseconds
|
private static final int OK_TIMEOUT = 5 * 1000; // Milliseconds
|
||||||
private static final int CONNECT_TIMEOUT = 2 * 60 * 1000; // Milliseconds
|
private static final int CONNECT_TIMEOUT = 2 * 60 * 1000; // Milliseconds
|
||||||
|
private static final int ESCAPE_SEQUENCE_GUARD_TIME = 1000; // Milliseconds
|
||||||
|
|
||||||
private final Executor executor;
|
private final Executor executor;
|
||||||
private final ReliabilityLayerFactory reliabilityFactory;
|
private final ReliabilityLayerFactory reliabilityFactory;
|
||||||
@@ -79,8 +80,10 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!foundBaudRate)
|
if(!foundBaudRate) {
|
||||||
|
tryToClose(port);
|
||||||
throw new IOException("No suitable baud rate");
|
throw new IOException("No suitable baud rate");
|
||||||
|
}
|
||||||
port.purgePort(PURGE_RXCLEAR | PURGE_TXCLEAR);
|
port.purgePort(PURGE_RXCLEAR | PURGE_TXCLEAR);
|
||||||
port.addEventListener(this);
|
port.addEventListener(this);
|
||||||
port.writeBytes("ATZ\r\n".getBytes("US-ASCII")); // Reset
|
port.writeBytes("ATZ\r\n".getBytes("US-ASCII")); // Reset
|
||||||
@@ -90,6 +93,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
throw new IOException(e.toString());
|
throw new IOException(e.toString());
|
||||||
}
|
}
|
||||||
// Wait for the event thread to receive "OK"
|
// Wait for the event thread to receive "OK"
|
||||||
|
boolean success = false;
|
||||||
try {
|
try {
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
@@ -98,13 +102,14 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
wait(end - now);
|
wait(end - now);
|
||||||
now = System.currentTimeMillis();
|
now = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
if(initialised) return true;
|
success = initialised;
|
||||||
}
|
}
|
||||||
} catch(InterruptedException e) {
|
} catch(InterruptedException e) {
|
||||||
tryToClose(port);
|
tryToClose(port);
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
throw new IOException("Interrupted while initialising");
|
throw new IOException("Interrupted while initialising");
|
||||||
}
|
}
|
||||||
|
if(success) return true;
|
||||||
tryToClose(port);
|
tryToClose(port);
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
@@ -132,6 +137,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
try {
|
try {
|
||||||
stateChange.acquire();
|
stateChange.acquire();
|
||||||
} catch(InterruptedException e) {
|
} catch(InterruptedException e) {
|
||||||
|
tryToClose(port);
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
throw new IOException("Interrupted while waiting to stop");
|
throw new IOException("Interrupted while waiting to stop");
|
||||||
}
|
}
|
||||||
@@ -163,7 +169,14 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
reliability.stop();
|
reliability.stop();
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Hanging up");
|
if(LOG.isLoggable(INFO)) LOG.info("Hanging up");
|
||||||
try {
|
try {
|
||||||
port.setDTR(false);
|
Thread.sleep(ESCAPE_SEQUENCE_GUARD_TIME);
|
||||||
|
port.writeBytes("+++".getBytes("US-ASCII"));
|
||||||
|
Thread.sleep(ESCAPE_SEQUENCE_GUARD_TIME);
|
||||||
|
port.writeBytes("ATH\r\n".getBytes("US-ASCII"));
|
||||||
|
} catch(InterruptedException e) {
|
||||||
|
tryToClose(port);
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
throw new IOException("Interrupted while hanging up");
|
||||||
} catch(SerialPortException e) {
|
} catch(SerialPortException e) {
|
||||||
tryToClose(port);
|
tryToClose(port);
|
||||||
throw new IOException(e.toString());
|
throw new IOException(e.toString());
|
||||||
@@ -246,6 +259,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
try {
|
try {
|
||||||
stateChange.acquire();
|
stateChange.acquire();
|
||||||
} catch(InterruptedException e) {
|
} catch(InterruptedException e) {
|
||||||
|
tryToClose(port);
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
throw new IOException("Interrupted while waiting to hang up");
|
throw new IOException("Interrupted while waiting to hang up");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ class ReliabilityLayerImpl implements ReliabilityLayer, WriteHandler {
|
|||||||
byte[] b = null;
|
byte[] b = null;
|
||||||
while(now < next && b == null) {
|
while(now < next && b == null) {
|
||||||
b = writes.poll(next - now, MILLISECONDS);
|
b = writes.poll(next - now, MILLISECONDS);
|
||||||
|
if(!running) return;
|
||||||
now = System.currentTimeMillis();
|
now = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
if(b == null) {
|
if(b == null) {
|
||||||
@@ -94,13 +95,11 @@ class ReliabilityLayerImpl implements ReliabilityLayer, WriteHandler {
|
|||||||
|
|
||||||
// The transport calls this method to pass data up to the SLIP decoder
|
// The transport calls this method to pass data up to the SLIP decoder
|
||||||
public void handleRead(byte[] b) throws IOException {
|
public void handleRead(byte[] b) throws IOException {
|
||||||
if(!running) throw new IOException("Connection closed");
|
if(running) decoder.handleRead(b);
|
||||||
decoder.handleRead(b);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The SLIP encoder calls this method to pass data down to the transport
|
// The SLIP encoder calls this method to pass data down to the transport
|
||||||
public void handleWrite(byte[] b) throws IOException {
|
public void handleWrite(byte[] b) {
|
||||||
if(!running) throw new IOException("Connection closed");
|
if(running && b.length > 0) writes.add(b);
|
||||||
if(b.length > 0) writes.add(b);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user