Skip to content

Commit

Permalink
Issue #212: Added missing connect() method to allow connecting transp…
Browse files Browse the repository at this point in the history
…orts manually
  • Loading branch information
hypfvieh committed May 18, 2023
1 parent 7b34e88 commit 2570a2f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ The library will remain open source and MIT licensed and can still be used, fork

##### Changes in 4.3.1 (not released yet):
- Provide classloader to ServiceLoader in TransportBuilder (for loading actual transports) and AbstractTransport (for loading IMessageReader/Writer implementations), thanks to [cthbleachbit](https://github.com/cthbleachbit) ([#210](https://github.com/hypfvieh/dbus-java/issues/210), [PR#211](https://github.com/hypfvieh/dbus-java/issues/211))
- Added missing `connect()` method to `AbstractTransport` to allow connecting the underlying transport manually, thanks to [brett-smith](https://github.com/brett-smith) ([#212](https://github.com/hypfvieh/dbus-java/issues/212)


##### Changes in 4.3.0 (2023-03-10):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,26 @@ public boolean isConnected() {
return transport != null && transport.isConnected();
}

/**
* Connects the underlying transport if it is not already connected.
* <p>
* Will work for both, client and server (listening) connections.
* </p>
*
* @return true if connection established or already connected, false otherwise
* @throws IOException when connection was not already established and creating the connnection failed
*/
public boolean connect() throws IOException {
if (!transport.isConnected()) {
if (transport.isListening()) {
return transport.listen() != null;
} else {
return transport.connect() != null;
}
}
return false;
}

protected Queue<Error> getPendingErrorQueue() {
return pendingErrorQueue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ public final SocketChannel connect() throws IOException {
return transportConnection.getChannel();
}

/**
* True if this transport connection is a listening (server) connection.
*
* @return boolean
*/
public final boolean isListening() {
return getAddress().isListeningSocket();
}

/**
* Start listening on created transport.<br>
* <p>
Expand All @@ -145,7 +154,8 @@ public final SocketChannel connect() throws IOException {
* Therefore this method should be called in a loop to accept multiple clients
* </p>
*
* @return {@link TransportConnection} containing created {@link SocketChannel} and {@link IMessageReader}/{@link IMessageWriter}
* @return {@link TransportConnection} containing created {@link SocketChannel} and
* {@link IMessageReader}/{@link IMessageWriter}
* @throws IOException if connection fails
*/
public final TransportConnection listen() throws IOException {
Expand Down

0 comments on commit 2570a2f

Please sign in to comment.