summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Johnson <mjj29@hecate.trinhall.cam.ac.uk>2007-01-03 14:51:15 +0000
committerMatthew Johnson <mjj29@hecate.trinhall.cam.ac.uk>2007-01-03 14:51:15 +0000
commitcb9a4e81e355b2c6ddb92c2bbbfc0467b5227644 (patch)
tree9c46d85ad5c7317326c566e28654e2e9ad4dd1a0
parent4244a9168e5b3a9e28a328235cc4b9530875e24c (diff)
set read timeout
-rw-r--r--TODO2
-rw-r--r--org/freedesktop/dbus/AbstractConnection.java9
-rw-r--r--org/freedesktop/dbus/DBusConnection.java2
-rw-r--r--org/freedesktop/dbus/DirectConnection.java2
-rw-r--r--org/freedesktop/dbus/Transport.java25
5 files changed, 23 insertions, 17 deletions
diff --git a/TODO b/TODO
index 54b925b..5fb0030 100644
--- a/TODO
+++ b/TODO
@@ -1,4 +1,4 @@
- * check recv thread is exiting properly, maybe call in.close()?
+ * Javadoc
* add header checks to daemon
* add TERM/etc handler to DBusDaemon
* autolaunch
diff --git a/org/freedesktop/dbus/AbstractConnection.java b/org/freedesktop/dbus/AbstractConnection.java
index a7dfc08..e3d9415 100644
--- a/org/freedesktop/dbus/AbstractConnection.java
+++ b/org/freedesktop/dbus/AbstractConnection.java
@@ -57,7 +57,7 @@ public abstract class AbstractConnection
// read from the wire
try {
// this blocks on outgoing being non-empty or a message being available.
- m = readIncoming(TIMEOUT, outgoing);
+ m = readIncoming();
if (m != null) {
if (Debug.debug) Debug.print(Debug.VERBOSE, "Got Incoming Message: "+m);
synchronized (this) { notifyAll(); }
@@ -178,9 +178,9 @@ public abstract class AbstractConnection
}
}
/**
- * Timeout in ms on checking the BUS for incoming messages and sending outgoing messages
+ * Timeout in us on checking the BUS for incoming messages and sending outgoing messages
*/
- private static final int TIMEOUT = 1;
+ protected static final int TIMEOUT = 100000;
/** Initial size of the pending calls map */
private static final int PENDING_MAP_INITIAL_SIZE = 10;
static final String BUSNAME_REGEX = "^[-_a-zA-Z][-_a-zA-Z0-9]*(\\.[-_a-zA-Z][-_a-zA-Z0-9]*)*$";
@@ -773,10 +773,9 @@ public abstract class AbstractConnection
if (e instanceof IOException) disconnect();
}
}
- private Message readIncoming(int timeoutms, EfficientQueue outgoing) throws DBusException
+ private Message readIncoming() throws DBusException
{
if (null == transport) throw new NotConnected("No transport present");
- // TODO do something with timeoutms and outgoing
Message m = null;
try {
m = transport.min.readMessage();
diff --git a/org/freedesktop/dbus/DBusConnection.java b/org/freedesktop/dbus/DBusConnection.java
index 8bf89de..d19d3e5 100644
--- a/org/freedesktop/dbus/DBusConnection.java
+++ b/org/freedesktop/dbus/DBusConnection.java
@@ -151,7 +151,7 @@ public class DBusConnection extends AbstractConnection
}
try {
- transport = new Transport(addr);
+ transport = new Transport(addr, AbstractConnection.TIMEOUT);
} catch (IOException IOe) {
if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, IOe);
throw new DBusException("Failed to connect to bus "+IOe.getMessage());
diff --git a/org/freedesktop/dbus/DirectConnection.java b/org/freedesktop/dbus/DirectConnection.java
index 98ef43c..2753258 100644
--- a/org/freedesktop/dbus/DirectConnection.java
+++ b/org/freedesktop/dbus/DirectConnection.java
@@ -38,7 +38,7 @@ public class DirectConnection extends AbstractConnection
super(address);
try {
- transport = new Transport(addr);
+ transport = new Transport(addr, AbstractConnection.TIMEOUT);
} catch (IOException IOe) {
if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, IOe);
throw new DBusException("Failed to connect to bus "+IOe.getMessage());
diff --git a/org/freedesktop/dbus/Transport.java b/org/freedesktop/dbus/Transport.java
index 536a28d..9dd86f3 100644
--- a/org/freedesktop/dbus/Transport.java
+++ b/org/freedesktop/dbus/Transport.java
@@ -685,19 +685,23 @@ public class Transport
{
connect(new BusAddress(address));
}
+ public Transport(String address, int timeout) throws IOException
+ {
+ connect(new BusAddress(address), timeout);
+ }
public void connect(String address) throws IOException
{
- connect(new BusAddress(address), true);
+ connect(new BusAddress(address), 0);
}
- public void connect(String address, boolean blocking) throws IOException
+ public void connect(String address, int timeout) throws IOException
{
- connect(new BusAddress(address), blocking);
+ connect(new BusAddress(address), timeout);
}
public void connect(BusAddress address) throws IOException
{
- connect(address, true);
+ connect(address, 0);
}
- public void connect(BusAddress address, boolean blocking) throws IOException
+ public void connect(BusAddress address, int timeout) throws IOException
{
if (Debug.debug) Debug.print(Debug.INFO, "Connecting to "+address);
this.address = address;
@@ -751,12 +755,15 @@ public class Transport
throw new IOException("Failed to auth");
}
if (null != us) {
- if (Debug.debug) Debug.print(Debug.VERBOSE, "Setting "+(blocking?"":"non-")+"blocking on UnixSocket");
- us.setBlocking(blocking);
+ if (Debug.debug) Debug.print(Debug.VERBOSE, "Setting timeout to "+timeout+" on Socket");
+ if (timeout == 1)
+ us.setBlocking(false);
+ else
+ us.setSoTimeout(timeout);
}
if (null != s) {
- if (Debug.debug) Debug.print(Debug.VERBOSE, "Setting "+(blocking?"":"non-")+"blocking on Socket");
- s.setSoTimeout(blocking ? 0 : 1);
+ if (Debug.debug) Debug.print(Debug.VERBOSE, "Setting timeout to "+timeout+" on Socket");
+ s.setSoTimeout(timeout);
}
mout = new MessageWriter(out);
min = new MessageReader(in);